Found 6710 Articles for Javascript

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

How to check for null, undefined, or blank variables in JavaScript?

Shubham Vora
Updated on 08-Aug-2022 08:38:34

17K+ 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

How do you check if a variable is an array in JavaScript?

Rahul Sharma
Updated on 13-Jun-2020 13:24:23

212 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');         }                  

How can I reimplement JavaScript delete method?

Sravani Alamanda
Updated on 08-Dec-2022 09:38:12

324 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

How do I Create Dynamic Variable Names Inside a JavaScript Loop?

Shubham Vora
Updated on 29-Nov-2024 11:25:08

16K+ Views

To create dynamic variable names inside a JavaScript loop, means it is not hardcoded already, and we can create it according to our needs from some other string values. For achieving this, we will be understanding four different approaches. In this article our task is to create dynamic variable names inside a JavaScript loop. Approaches to Create Dynamic Variable Names Here is a list of approaches to create dynamic variable names inside a JavaScript loop which we will be discussing in this article with stepwise explanation and complete example codes. Using Array ... Read More

Which data is stored in var and how its content is changed in JavaScript?

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

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

What are the differences between “untyped” & “dynamically typed” programming languages?

Nikitasha Shrivastava
Updated on 23-Apr-2025 14:42:23

2K+ Views

When learning different programming languages, you may come across terms like untyped and dynamically typed. While they may sound similar but they have different concepts in how programming languages manage data types. In this article, we will see these concepts in simple terms with simple examples. Untyped Language Untyped programming languages do not have a strict definition of data types. This allows you to use values without providing the data type. The interpreter or execution environment will handle everything anyway it considers a match. Example Let us look at an example that uses an untyped language - # ... Read More

Must you define a data type when declaring a variable in JavaScript?

Amit Sharma
Updated on 03-Jan-2020 10:54:26

143 Views

In JavaScript, variables are defined using the var keyword followed by the variable name. Before you use a variable in a JavaScript program, you must declare it. Variables are declared with the var keyword as follows.var rank;A data type isn’t needed in JavaScript. Variables in JavaScript are not handled like other strong typed language C++, Java, etc.Storing a value in a variable is called variable initialization. You can do variable initialization at the time of variable creation or at a later point in time when you need that variable.    var name = "Amit";    var rank = 2;

How are variables allocated memory in JavaScript?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:21

392 Views

JavaScript handling of the variable is different from other programming languages C, C++., Java, etc. Variables in JavaScript 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. Before you use a variable in a JavaScript program, you must declare it. Variables are declared with the var keyword as follows. var rank; var points; Storing a value in a variable is called variable initialization. You can do variable initialization at the time of variable creation or at a ... Read More

What does “javascript:void(0)” mean?

Shubham Vora
Updated on 31-Oct-2022 11:27:30

5K+ Views

In this tutorial, we will learn what “javascript: void(0)” means. In English, void means nothing. In a programming language, void means return nothing. “javascript: void(0)” is similar to void. javascript: void(0) means return undefined as a primitive value. We use this to prevent any negative effects on a webpage when we insert some expression. For example, in the case of URL hyperlinks. Hyperlinks open by reloading the page when the user clicks on the link. When you need to run some other code in such cases, you can use javascript: void(0). Let’s split javascript: void(0) with a colon. We get ... Read More

Advertisements