- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6685 Articles for Javascript
![Shubham Vora](https://www.tutorialspoint.com/assets/profiles/485898/profile/60_1456867-1657516792.jpeg)
1K+ Views
In this tutorial, we will look at a few ways to prevent duplicate JavaScript variable declarations and comparison between them from understanding which one is suitable in a given context. The best way to prevent duplicate variable declaration is to avoid creating global variables. Let’s move forward to discuss this. Wrapping Code Within a Function Here, the variables declared inside the function are not accessible outside the function and vice versa. Users can follow the syntax below for using this method. Syntax (function(){ var varNam = "test"; }()) Here varNam is wrapped inside a function. Example ... Read More
![Shubham Vora](https://www.tutorialspoint.com/assets/profiles/485898/profile/60_1456867-1657516792.jpeg)
4K+ Views
In this tutorial, we will learn different approaches to checking if a JavaScript variable is of function type or not. In JavaScript, the function contains the block of code, making the code reusability better.There are mainly two ways to declare the functions, one is a named function, and another is an anonymous function. While declaring the anonymous function, we need to store it in some variable to access it from somewhere in our code or call that function.Here, users can see how to declare the anonymous function and store it into the variable.let tutorialspoint = function() { //code for the ... Read More
![Sai Subramanyam](https://www.tutorialspoint.com/assets/profiles/13512/profile/60_68191-1512710774.jpg)
15K+ Views
To unset a variable in JavaScript, use the undefined. After that, use delete operator to completely remove it.Let’s try the code snippet again.var str = “Demo Text”; window.onscroll = function() { var y = this.pageYOffset; if(y > 200) { document.write(nxt); nxt = undefined; // unset delete(nxt); // this removes the variable completely document.write(nxt); // the result will be undefined } }
![Swarali Sree](https://www.tutorialspoint.com/assets/profiles/13515/profile/60_84115-1512649510.jpg)
600 Views
On getting the result of the following, you can find whether a variable is null or undefined. If the result is “false”, it means the variable is null and undefined.Here, the variable results in “True” − var age = 10; if(age) { document.write("True"); } else { document.write("False"); }
![Shubham Vora](https://www.tutorialspoint.com/assets/profiles/485898/profile/60_1456867-1657516792.jpeg)
6K+ Views
In this article, we will learn what characters are valid for JavaScript variable names. We use variables to save values. First, we have to define the variable, and then we can assign a value to it. We can use the variable name to access the variable in the code. With a variable name, we can reassign its value. As you adhere to a few principles, variable names are quite versatile. Rules A letter, dollar sign($), or underscore (_) must make up the first character. A number cannot be the initial character. Any letter, number, or underscore can complete the ... Read More
![Shubham Vora](https://www.tutorialspoint.com/assets/profiles/485898/profile/60_1456867-1657516792.jpeg)
15K+ Views
In this tutorial, we will learn to check for null, undefined, or blank variables in JavaScript. There is no particular built-in library function to check whether a variable is undefined or null. Still, we can use some operators such as typeof operator and equality operator to check the variable. Before we proceed with the tutorial, let’s clear the doubt between the null, undefined, or blank variable. Null VS Undefined We can say that the Null and undefined variables are almost the same but not identical. Undefined variable − It is a variable not declared in the program, and the ... Read More
![Rahul Sharma](https://www.tutorialspoint.com/assets/profiles/14297/profile/60_102977-1513054044.jpg)
129 Views
To check if a variable is an array, use “instanceof. The following is the syntax −variable instanceof ArrayExampleLet’s seen an example to check if the variable “sports” is an array or not? var sports = [ "tennis", "football", "cricket" ]; if (sports instanceof Array) { alert('Array!'); } else { alert('Not an array'); }
![Sravani Alamanda](https://www.tutorialspoint.com/assets/profiles/507714/profile/60_44900-1661507911.jpg)
220 Views
The delete operator in JavaScript is used to remove properties from an object to remove element(s) from an array or to remove element(s) from a set object. Always remember the following points about delete: delete is a keyword in JavaScript, so it shouldn’t be altered, and you cannot use delete objects in single variables since it is used only for deleting properties of objects. Let's look in detail at how we can implement delete operators in JavaScript. Deleting object properties Objects in JavaScript, we will write using key-value pair like const Employee = { firstname: 'Devika', ... Read More
![Shubham Vora](https://www.tutorialspoint.com/assets/profiles/485898/profile/60_1456867-1657516792.jpeg)
14K+ Views
In this tutorial, we will use the dynamic variable names inside the JavaScript loop. The dynamic variables name means it is not hardcoded already, and we can create it according to our needs from some other string values.In JavaScript, there are not many applications of the dynamic variable, but it is needed while developing the real-time application. For example, while developing any application, the programmer wants to store any user-related entity to the variable with the same name as the username. In this scenario, programmers need to create dynamic variables inside JavaScript.Users can also refer to the below examples to ... Read More
![Amit Sharma](https://www.tutorialspoint.com/assets/profiles/14294/profile/60_103411-1513053466.png)
59 Views
JavaScript variables are not typed but their values do have a type. The same variable can be assigned new values.ExampleLive Demo var a; document.write(typeof a+"\r"); a = true; document.write(typeof a+"\r"); a = 5; document.write(typeof a+"\r"); a = "web"; document.write(typeof a+"\r");