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

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

Description

In JavaScript, fontsize() is a string method that is used to create the HTML aspect and specify a font size. Because the fontsize() technique is a technique of the String object, it need to be invoked through a unique occasion of the String class.

Syntax

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

string.fontsize(size_value);

Parameters or Arguments

size_value It is the font measurement that will be used as the measurement attribute for the element. It can be expressed as both a numeric or relative value. Numeric values vary from 1 to 7 (1 is the smallest, 7 is the largest, 3 is the default). Relative values can be values such as +1 or -2, increasing by using one font size or reducing via 2 font sizes, respectively.

Returns

The fontsize() technique returns a string containing a element. The fee of the size_value parameter is used as the measurement attribute for the element.

Note

The fontsize() technique does now not change the price of the unique string.

Example

Let’s take a seem at an example of how to use the fontsize() approach in JavaScript.

For example:

var totn_string = 'TechOnTheNet';

console.log(totn_string.fontsize(7));

In this example, we have declared a variable referred to as totn_string that is assigned the string price of ‘TechOnTheNet’. We have then invoked the fontsize() technique of the totn_string variable to return a string that includes the HTML issue with a font size.

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

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

<font size="7">TechOnTheNet</font>

As you can see, the fontsize() approach created a string that carries a element. The cost of the totn_string variable (which is ‘TechOnTheNet’) is enclosed inside the and tags. The font dimension value of 7 that was handed into the fontsize() method as a parameter is used as the measurement attribute for the element.