JavaScript String bold() Method
Last Updated :
04 Jun, 2024
Improve
The JavaScript bold() function of string values produces a string that includes this string within a <b> element ( <b>str</b> ), thus making this string be displayed in bold, in HTML5, it is supported, but for more complicated styling CSS is usually the best choice.
Note: String bold() is deprecated in JavaScript.
Syntax
string.bold()
Return Value:
A string embedded within a <b>
tag.
Parameters:
None.
Example 1: In the below example, we will see the basic usage of the JavaScript bold() method.
let str = "Hello, World!";
console.log(str.bold());
Output
<b>Hello, World!</b>
Example 2: In the below example, we will use bold() method with a concatenated string.
let str1 = "Hello, ";
let str2 = "World!";
console.log((str1 + str2).bold());
Output
<b>Hello, World!</b>
Example 3: In the given example, we will use nested HTML tags with bold() method.
let str = "Hello, <em>World!</em>";
console.log(str.bold());
Output
<b>Hello, <em>World!</em></b>