Using String sub() method to coding in Javascript/JS

This JavaScript tutorial explains how to use the string approach known as sub() with syntax and examples.


In JavaScript, sub() is a string method that is used to create the HTML element. Because the sub() approach is a technique of the String object, it should be invoked thru a specific occasion of the String class.


In JavaScript, the syntax for the sub() method is:


Parameters or Arguments

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


The sub() method returns a reproduction of string enclosed in and tags.


The sub() technique does now not change the cost of the unique string.


Let’s take a seem at an instance of how to use the sub() technique in JavaScript.

For example:

var totn_string = 'TechOnTheNet';


In this example, we have declared a variable called totn_string that is assigned the string cost of ‘TechOnTheNet’. We have then invoked the sub() technique of the totn_string variable to return a string that includes the HTML element.

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

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


As you can see, the sub() method created a string that consists of a element. The value of the totn_string variable (which is ‘TechOnTheNet’) is enclosed inside the and tags.