Found 10711 Articles for Web Development

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

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

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

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

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

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

Why would a jQuery variable start with a dollar sign?

Johar Ali
Updated on 13-Jun-2020 13:14:27

264 Views

When you will begin working about jQuery, you will get to know about the usage of the $ sign. A $ sign is used to define jQuery.jQuery variables begin with $ to distinguish them from a standard JavaScript object. Also, it is a convention. jQuery selectors start with the dollar sign and parentheses() − $.Let's take an Example −// jQuery object var $phone = $("#myphone"); // dom object var phone_el = $("#myphone").get(1);

How can I reimplement JavaScript delete method?

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

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

How do I create dynamic variable names inside a JavaScript loop?

Shubham Vora
Updated on 20-Jul-2022 08:30:09

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

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

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

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

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

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

74 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

277 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

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

What is the yield keyword in JavaScript?

Rahul Sharma
Updated on 13-Jun-2020 12:12:12

524 Views

The yield keyword is used in JavaScript to pause and resume a generator function. The value of the expression is returned to the generator's caller.Here are the Examples −function* displayRank () {    var selPlayers= [1, 2, 3, 4];    for (var a = 0; a < selPlayers.length; a++) {       yield selPlayers[i];    } }After defining a generator function, use it like the following. HHere displayRank() is the generator function −var rank = displayRank(); // // value: 1 alert(rank.next()); // value: 2 alert(rank.next()); // value: 3 alert(rank.next()); // value: 4 alert(rank.next()); // value: undefined alert(rank.next());

Advertisements