Found 10877 Articles for Web Development

What is the difference between substr() and substring() in JavaScript?

Alankritha Ammu
Updated on 15-Jun-2020 06:46:04

252 Views

The examples given above have the same output, but yes the method differs, with that the parameters too.The substring() method the second parameter is the index to stop the search, whereas the second parameter of substr() is the maximum length to return.ExampleLet’s see an example for substr() method in JavaScript −Live Demo           JavaScript String substr() Method                          var str = "Apples are round, and apples are juicy.";          document.write("(1, 2): " + str.substr(1, 2));          document.write("(-2, 2): ... Read More

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

388 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

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

22K+ 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 calculate the nth root of a number in JavaScript?

Saurabh Jaiswal
Updated on 06-Jan-2023 13:32:57

893 Views

We have given a number and the task is to calculate the nth root of that number using JavaScript. We have multiple ways to achieve this, some of which are the following. Using Math.pow() Method Using Logarithm To get the nth root of a number firstly let’s understand whose root we can calculate and which number’s root we cannot calculate. If the number is positive and the root is also even then we will get two solutions. E.g − 2nd root of 16 is +4 and -4, similarly 4th root of 16 is +2 and -2 If ... Read More

How to check whether a value is a number in JavaScript?

Shubham Vora
Updated on 14-Sep-2023 14:11:27

25K+ Views

In this tutorial, we will learn to check whether a value is a number in JavaScript. In JavaScript, it is necessary to check the variable's data type while performing some operation. Otherwise, it can create some unknown bugs in your application. For example, when users use the addition operator with the string, it concatenates the two strings, and in the same way, if users use the addition operator with a number, it adds two numbers. Now, think that the user wants to add two numbers but is concatenating the two strings. Here, we have three different methods to check whether ... Read More

How can I round a number to 1 decimal place in JavaScript?

Shubham Vora
Updated on 14-Jul-2022 11:51:13

21K+ Views

In this tutorial, we will learn to round a number to a one decimal place in JavaScript. There are various needs to round the float numbers and show particular digits after the decimal point.In our case, we need to show only the digit after the decimal point. However, we will create a customizable manual function that can round off the number and show the particular number of digits after the decimal point at the end of this tutorial.This example lets users understand the fundamental need to round a number to a single decimal digit. Suppose the scenario where you are ... Read More

How to use GoJS HTML5 Canvas Library for drawing diagrams and graphs?

Nancy Den
Updated on 25-Feb-2020 07:01:47

334 Views

GoJS is a JavaScript library, which you can use to implement interactive diagrams. This page will show you the essentials of using GoJS. If you want to add diagrams and graphs, then use this library, which is Open Source.GoJS has a model-view architecture, in which Models holds arrays of JavaScript objects, which describe nodes and links. To visualize this data using actual Node and Link objects, the Diagrams act as views.Constructing a Diagram with GoJS creates an HTML5 Canvas element to be placed inside the given DIV element.How to draw a diagramStart working with GoJS, you need to declare the ... Read More

How can I force clients to refresh JavaScript files?

Shubham Vora
Updated on 10-Aug-2022 11:36:46

9K+ Views

This tutorial teaches us to force clients to refresh JavaScript files. Now, the question is, why do we need to force clients to refresh the JavaScript files? Let’s understand it by example issue. Suppose we have deployed the application and lots of users are using our application. Now, to improve the performance and UI of the application, we will continuously work on our application and upgrade its version after every period. Obviously, after upgrading our application’s version, we will also push that into production. But sometimes, on the user's screen, client-side JavaScript or CSS is not upgraded, and it shows the ... Read More

Advertisements