How to make a text italic using JavaScript

In JavaScript, the italics() method is used to display an italic string. It makes the text similar to the text is in (italic tag). Because the italics() method is a method of string object, so it must be invoked through a specific instance of the string class.

It is responsible for the italicization of string. It does not change the value of the original string; instead, it returns the italicized string.

Generally, this method returns the string in the format given below. Suppose we have a string "Hello world!" and we are applying the italics() method on it and display the output using the alert method, then we will get -

The output will be a string written in the tag.

Syntax

This method does not require any arguments. Now, let's understand the use of italics() method by using some illustrations.

Example1

In this example, we are italicizing a string. Here, there is string str on which we are applying the italicize method to make the characters of the string italic.

We have to click the given HTML button to see the output. Here we are using the document.write() method to show the output.

Test it Now

Output

After the execution of the code and clicking the given HTML button the output will be -

How to make a text italic using JavaScript

Now, in the next example, we are displaying the output using the alert() method. Let's see the result of the next example. We might get a different result.

Example2

We have to click the given HTML button to see the output.

Test it Now

Output

After the execution of the code and clicking the given HTML button the output will be -

How to make a text italic using JavaScript

We can see the format of the output using the alert() method. Although we are applying the same method on the same string in both examples, but the format of the output is different.






Contact US

Email:[email protected]

How to make a text italic using JavaScript
10/30