JavaScript: String bold() method
This JavaScript tutorial explains how to use the string method called bold() with syntax and examples.
Description
In JavaScript, bold() is a string method that is used to create the HTML <b> element. Because the bold() method is a method of the String object, it must be invoked through a particular instance of the String class.
Syntax
In JavaScript, the syntax for the bold() method is:
string.bold();
Parameters or Arguments
There are no parameters or arguments for the bold() method.
Returns
The bold() method returns a copy of string enclosed in <b> and </b> tags.
Note
- The bold() method does not change the value of the original string.
Example
Let's take a look at an example of how to use the bold() method in JavaScript.
For example:
var totn_string = 'TechOnTheNet';
console.log(totn_string.bold());
In this example, we have declared a variable called totn_string that is assigned the string value of 'TechOnTheNet'. We have then invoked the bold() method of the totn_string variable to return a string that contains the HTML <b> element.
We have written the output of the bold() method to the web browser console log, for demonstration purposes, to show what the bold() method returns.
The following will be output to the web browser console log:
<b>TechOnTheNet</b>
As you can see, the bold() method created a string that contains a <b> element. The value of the totn_string variable (which is 'TechOnTheNet') is enclosed within the <b> and </b> tags.
Advertisements