totn JavaScript

JavaScript: String italics() method

This JavaScript tutorial explains how to use the string method called italics() with syntax and examples.

Description

In JavaScript, italics() is a string method that is used to create the HTML <i> element. Because the italics() 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 italics() method is:

string.italics();

Parameters or Arguments

There are no parameters or arguments for the italics() method.

Returns

The italics() method returns a copy of string enclosed in <i> and </i> tags.

Note

  • The italics() method does not change the value of the original string.

Example

Let's take a look at an example of how to use the italics() method in JavaScript.

For example:

var totn_string = 'TechOnTheNet';

console.log(totn_string.italics());

In this example, we have declared a variable called totn_string that is assigned the string value of 'TechOnTheNet'. We have then invoked the italics() method of the totn_string variable to return a string that contains the HTML <i> element.

We have written the output of the italics() method to the web browser console log, for demonstration purposes, to show what the italics() method returns.

The following will be output to the web browser console log:

<i>TechOnTheNet</i>

As you can see, the italics() method created a string that contains an <i> element. The value of the totn_string variable (which is 'TechOnTheNet') is enclosed within the <i> and </i> tags.