Found 7019 Articles for Javascript

How to get the last index of an occurrence of the specified value in a string in JavaScript?

Shubham Vora
Updated on 20-Oct-2022 08:02:40

375 Views

In this tutorial, we will learn how to get the last index of an occurrence of the specified value in a string in JavaScript. The last index of an occurrence means the last position found of the searched item in a given string. It can be a single character or a word also. To find the index of the last occurrence, we have a method in JavaScript that is the lastIndexOf() method. Using the lastIndexOf() Method This method will search the whole string and return the index of that value's last position. If it doesn’t find the item, it ... Read More

What are the methods of a boolean object in JavaScript?

Shubham Vora
Updated on 15-Nov-2022 10:59:55

186 Views

In this tutorial, we will learn what are the methods of a boolean object in JavaScript. First, we will learn about what is a boolean object. The boolean object represents two values: ‘true’ and ‘false’. The boolean object’s default value is false if the value parameter is missing, 0, -0, null, false, NaN, undefined, or the empty string (‘’). The Boolean object value will be set to true for any other values. The boolean objects have some properties such as constructor and prototype and some methods like toString() and valueOf(). Here we will emphasize these two methods. Users can follow ... Read More

What are the properties of a boolean object in JavaScript?

Shubham Vora
Updated on 31-Oct-2022 12:26:52

305 Views

In this tutorial, we will learn what the properties of a boolean object in JavaScript are. The Boolean object represents two values: ‘true’ or ‘false.’ If the value parameter is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (‘’), the object has the value false as its default. Any other values will set the Boolean object value to true. In addition, the Boolean object has properties such as constructor and prototype and methods such as toString() and valueOf(). Users can follow the below syntax to initialize a Boolean object. Syntax const boolean_object = new Boolean(value/expression) ... Read More

How to initialize a boolean array in JavaScript?

Shubham Vora
Updated on 14-Sep-2022 13:47:32

3K+ Views

In this tutorial, we will learn how to initialize a boolean array in JavaScript. We can initialize a boolean array in JavaScript in three ways− Using the fill() Method Using the Array from() Method Using the for Loop Using the fill() Method We can initialize a boolean array using the fill() method. The fill() method sets the static value of all array elements from the beginning index to the end index. Syntax //initialization of boolean array with fill() method let arrayName = new Array(array_length).fill(true/false); In the above syntax, we create an array with the name "arrayName" ... Read More

How to check if a variable is boolean in JavaScript?

Shubham Vora
Updated on 08-Aug-2022 08:47:37

21K+ Views

In this tutorial, we will learn to check if the variable is a Boolean in JavaScript. In JavaScript, if we match the two different variables with the same value and different data types using the equality operator, it returns a true value. It means if we compare a twovariable with the true value but different data types such as Boolean and string, it will generate a positive result. To overcome these problems, we need to check if the variable is of type Boolean or not before matching it with other values. Users can use the three methods below to check ... Read More

How to declare a boolean in JavaScript?

Ayyan
Updated on 15-Jun-2020 06:24:05

2K+ Views

To declare a Boolean in JavaScript, you need to assign true or false value.var answer = true;ExampleTo learn about the working of Boolean, let’s see the following example −Live Demo           JavaScript Boolean                        var num1 = 10;          var num2 = 20;          document.write(num1 > num2);          

How to create a Boolean object in JavaScript?

Anjana
Updated on 15-Jun-2020 06:22:59

210 Views

The Boolean object represents two values, either "true" or "false". If the value parameter is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of false.Create a Boolean object like this −var val = new Boolean(value);ExampleYou can try to run the following code to learn how to create a Boolean object −Live Demo           JavaScript toString() Method                        var flag = new Boolean(true);          document.write( "flag.toString is : " + flag.toString() );          

What is Number.toExponential() method in JavaScript?

Abhishek
Updated on 06-Jan-2023 11:22:55

87 Views

In JavaScript, the Number.toExponential() method returns a string of a number representing the given number in its exponential form. This method is basically used to convert a number to its exponential form. Syntax The following syntax will show you how you can use the Number.toExponential() method to convert a number into its exponential value Number.toExponential( fractionDigits ); The fractionDigits parameter is an integer specifying the number of digits after the decimal point. Let us understand the implementation of the toExponential() method in details with the help of code examples Algorithm Step 1 − In the first step of the ... Read More

What is Number.NEGATIVE_INFINITY constant in JavaScript?

Abhishek
Updated on 06-Jan-2023 11:09:44

142 Views

Number.NEGATIVE_INFINITY is a special numeric value representing a value less than Number.MIN_VALUE. This value is represented as "-Infinity". It resembles infinity in its mathematical behavior. But it is different from the mathematical infinity in many ways as listed below − If the negative infinity is multiplied by NaN, the result will be NaN. When a negative infinity is multiplied by a positive infinity, the result will always be a negative infinity. If a negative infinity is multiplied by itself, then the result will always be positive infinity. Negative infinity, divided by positive infinity or by itself will return ... Read More

What are MAX_VALUE and MIN_VALUE in JavaScript?

Alankritha Ammu
Updated on 15-Jun-2020 06:08:53

203 Views

The Number.MAX_VALUE property belongs to the static Number object. It represents constants for the largest possible positive numbers that JavaScript can work with.The Number.MIN_VALUE property belongs to the static Number object. It represents constants for the smallest possible positive numbers that JavaScript can work with.ExampleYou can try to run the following code to learn about the MAX and MIN value in JavaScript −Live Demo                    function showMinValue() {             var val = Number.MIN_VALUE;             alert("Value of Number.MIN_VALUE : " + val ... Read More

Advertisements