Found 10711 Articles for Web Development

How to check if a variable is NaN in JavaScript?

Shubham Vora
Updated on 08-Aug-2022 08:45:55

8K+ Views

In this tutorial, we will learn to check if the variable is NaN in JavaScript. The full form of the NaN is ‘not a number’. The NaN is the reserved keyword in the JavaScript which we can assign to the variable. If users are using the below method to check whether a variable is a number or not, it will not work. var a = "Hello"; let result = a == NaN; // it always returns false. As we have talked that the above method will not work to check for a number because NaN is the reserved keyword. ... Read More

What is NaN in JavaScript?

Abhishek
Updated on 08-Nov-2022 06:40:59

498 Views

In this tutorial, we will learn about NaN in JavaScript. NaN is nothing more than a property of the global object which stands for Not a Number. It is mainly used to check whether the entered value is a number or not. The NaN and Number. NaN both are same, so do not confuse next time if Number. NaN is written in any program as it is similar to NaN. The NaN is a property that is rarely used in any program because it is not a good practice to use NaN to identify anything in the program. There is ... Read More

How to use 'const' keyword in JavaScript?

Abhishek Kumar
Updated on 10-Nov-2022 08:47:01

3K+ Views

We use the const keyword in JavaScript to declare variables whose value can be initialized only at the time of declaration. It is similar functionality of declaring variables as the other keywords provided in JavaScript i.e. var and let. const is short for constant, meaning that the value that resides in the variable is unchangeable. The const keyword in JavaScript It is used to declare variables in JavaScript. The variables created using const follow certain rules. The variable is block scoped. This means that the scope(lifetime) of the variable depends on the place where it has been declared. This ... Read More

Why is 'class' a reserved word in JavaScript?

Rahul Sharma
Updated on 13-Jun-2020 11:44:33

420 Views

The following are the future reserved words, which include ‘class’. These words are used as keywords in proposed extensions and are therefore reserved to allow for the possibility of future adoption of those extensions.class enum extends super const export ImportThe above is defined in the ECMAScript specification.In ECMAScript 6 Language Specification it is used. The class declaration creates a class −class name [extends] {    // body of class }

Why JavaScript 'var null' throw an error but 'var undefined' doesn't?

Johar Ali
Updated on 13-Jun-2020 11:42:53

91 Views

The web browser throws an error for “var null” because it is a reserved identifier.You cannot use the following literals as identifiers in ECMAScript −null frue falseundefined A property with no definition. It is not known and not a reserved identifier. Its type is undefined.nullIt is known and a reserved identifier. But “null” isn’t the same as “false”. When you will declare a variable and set it to null, then null will get printed.

What are Reserved Words in JavaScript?

Amit Sharma
Updated on 13-Jun-2020 11:40:24

363 Views

Reserved words cannot be used as JavaScript variables, functions, methods, loop labels, or any object names.Here are the reserved words in JavaScript −abstractElseinstanceofswitchbooleanEnumintsynchronizedbreakExportinterfacethisbyteExtendslongthrowcaseFalsenativethrowscatchFinalnewtransientcharFinallynulltrueclassFloatpackagetryconstForprivatetypeofcontinueFunctionprotectedvardebuggerGotopublicvoiddefaultIfreturnvolatiledeleteimplementsshortwhileDoImportstaticwithdoubleInsuper

What are Variable Naming Conventions in JavaScript

Ali
Ali
Updated on 13-Jun-2020 09:28:57

1K+ Views

While naming your variables in JavaScript, keep some rules in mind. The following are the variable naming conventions in JavaScript −You should not use any of the JavaScript reserved keywords as a variable name. These keywords are mentioned in the next section. For example, break or boolean variable names are not valid.JavaScript variable names should not start with a numeral (0-9). They must begin with a letter or an underscore character. For example, 123test is an invalid variable name but _123test is a valid one.JavaScript variable names are case-sensitive. For example, Name and name are two different variables.Here are the Examples  −var name; // correct var 2name; ... Read More

How to name variables in JavaScript?

Rahul Sharma
Updated on 13-Jun-2020 09:27:04

239 Views

Variables can be thought of as named containers. You can place data into these containers and then refer to the data simply by naming the container.While naming your variables in JavaScript, keep the following rules in mind.You should not use any of the JavaScript reserved keywords as a variable name. These keywords are mentioned in the next section. For example, break or boolean variable names are not valid.JavaScript variable names should not start with a numeral (0-9). They must begin with a letter or an underscore character. For example, 123test is an invalid variable name but _123test is a valid one.JavaScript variable names are ... Read More

How to replace all occurrences of a string in JavaScript?

Prabhdeep Singh
Updated on 07-Nov-2022 06:20:23

11K+ Views

This tutorial will teach us how to replace all occurrences of a string in JavaScript which mean by the end of the tutorial we will learn to detect a given type of substring from the given string and replace it will another given string by the user. To replace all occurrences of a string in JavaScript we have three methods which we are going to see in this tutorial, they are: splitting the string into an array and then joining it back by adding replacement in gaps, with the global regular expression using the replace() method, and at last we ... Read More

How is JavaScript an untyped language?

Saurabh Jaiswal
Updated on 11-Aug-2022 11:46:09

780 Views

JavaScript is an untyped language because in JavaScript the variables can hold any data type meaning that JavaScript does not have a type declaration and when the variable is created we do not need to specify any data type unlike other programming languages like Java, C#, C++, etc. which needs int, char, float, etc. to create a variable. In JavaScript we use var, let, and const to create a variable. One of the best parts of untyped language is it gives the flexibility to reassign any type of value to a variable, it doesn't matter whether the initialized value was ... Read More

Advertisements