Found 10711 Articles for Web Development

How to check for “undefined” variable in JavaScript?

Samual Sam
Updated on 30-Jul-2019 22:30:21

155 Views

On getting the result of the following, you can find whether a variable is ‘undefined’. If the result is “false”, it means the variable is undefined. Here, the variable results in “True” Example Live Demo var res = 10; if(res) { document.write("True"); } else { document.write("False"); }

How to generate random whole numbers in JavaScript in a specific range?

Amit Sharma
Updated on 15-Jun-2020 05:25:14

175 Views

To generate a random number, use the JavaScript Math.random() method. Here set the minimum and maximum value and generate a random number between them as in the following code −ExampleLive Demo                    var max = 6          var min = 2          var random = Math.floor(Math.random() * (max - min + 1)) + min;          document.write(random)          

How to pass JavaScript Variables with AJAX calls?

Shubham Vora
Updated on 15-Sep-2022 11:53:13

8K+ Views

In this tutorial, we will learn how to pass JavaScript Variables with AJAX calls. AJAX stands for Asynchronous JavaScript and XML. As the name suggests, it performs asynchronous operations on your web page. AJAX communicates with the server by HTTP requests and gets the required data as an HTTP response. We can control these HTTP requests by passing the JavaScript variables with AJAX calls. There are various types of HTTP requests, and in this tutorial, we will discuss the most popular HTTP requests by using AJAX and also pass JavaScript variables with it. Pass JavaScript Variables with “GET” AJAX calls ... Read More

Where are JavaScript variables stored?

Samual Sam
Updated on 07-Jan-2020 06:58:27

1K+ Views

Like many other programming languages, JavaScript has variables. 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.JavaScript variables get stored in the memory of the browser process. The following ways can work for storing variables:The variables which you declare in your JavaScript code gets saved in the memory of the browser process.Cookies can also store variables, they are often saved on your hard disk;

What is the best way of declaring multiple Variables in JavaScript?

Amit Sharma
Updated on 13-Sep-2019 07:37:26

125 Views

Definitely, the following way of declaring multiple variables is more efficient:var variable1 = 5; var variable2 = 3.6; var variable3 = “Amit”;Suppose you need to add, remove, or update a variable, then you can easily do it.But with the following method, you need to do more changes. For example, on removing a variable, you need to remove the semi-colon. If it’s the first, then you need to add var to the second variable.var variable1 = 5, variable2 = 3.6, variable3 = “Amit”

How to prevent duplicate JavaScript Variables Declaration?

Shubham Vora
Updated on 14-Sep-2022 13:42:57

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

How can I check if a JavaScript variable is function type?

Shubham Vora
Updated on 12-Jul-2022 13:38:18

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

How to unset a JavaScript variable?

Sai Subramanyam
Updated on 13-Sep-2019 07:44:06

16K+ 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 } }

How to determine if a variable is 'undefined' or 'null'?

Swarali Sree
Updated on 15-Jun-2020 09:13:24

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");          }          

What characters are valid for JavaScript variable names?

Shubham Vora
Updated on 31-Oct-2022 11:23:19

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

Advertisements