Articles on Trending Technologies

Technical articles with clear explanations and examples

How to unset a JavaScript variable?

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 18K+ Views

To unset a variable in JavaScript, you can set it to undefined or use the delete operator for object properties. However, the approach depends on how the variable was declared. Setting Variable to undefined The most common way to unset a variable is by assigning undefined to it: let userName = "John Doe"; console.log("Before:", userName); // Unset the variable userName = undefined; console.log("After:", userName); Before: John Doe After: undefined Using delete Operator The delete operator works only on object properties, not on variables declared with var, let, or const: ...

Read More

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

Swarali Sree
Swarali Sree
Updated on 15-Mar-2026 937 Views

In JavaScript, checking for null and undefined values is a common requirement. There are several approaches to determine if a variable is null or undefined. Understanding null vs undefined undefined means a variable has been declared but not assigned a value, while null is an intentional absence of value. let undefinedVar; let nullVar = null; ...

Read More

What characters are valid for JavaScript variable names?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 6K+ Views

In JavaScript, variable names must follow specific rules to be valid. Understanding these rules helps you write error-free code and follow good naming practices. Variables store values that can be accessed and modified throughout your program. The variable name acts as an identifier to reference the stored value. Basic Rules for Variable Names Must start with a letter (a-z, A-Z), dollar sign ($), or underscore (_). Cannot start with a number. After the first character, can contain letters, numbers (0-9), dollar signs, or underscores. Variable names are ...

Read More

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

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 17K+ Views

In JavaScript, checking for null, undefined, or blank variables is a common task. There's no single built-in function to check all these states, but we can use operators like typeof and equality operators to handle each case effectively. Let's first understand the differences between these variable states: Null vs Undefined vs Blank Undefined variable − A variable that has been declared but not assigned a value, or a variable that doesn't exist. Null variable − A variable that has been intentionally assigned the value null to represent "no value". Blank variable − Usually refers to empty ...

Read More

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

Rahul Sharma
Rahul Sharma
Updated on 15-Mar-2026 309 Views

JavaScript provides several methods to check if a variable is an array. The most reliable and recommended approach is Array.isArray(), though instanceof Array also works in most cases. Using Array.isArray() (Recommended) The Array.isArray() method is the standard and most reliable way to check if a variable is an array. var sports = ["tennis", "football", "cricket"]; var name = "John"; var obj = {a: 1, b: 2}; if (Array.isArray(sports)) { alert('sports is an Array!'); } else { alert('sports is not an array'); } if ...

Read More

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

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 17K+ Views

Creating dynamic variable names inside a JavaScript loop means generating variable names programmatically during runtime rather than hardcoding them. This technique is useful when you need to create multiple variables based on user input, API responses, or iterative patterns. In this article, we'll explore four different approaches to create dynamic variable names inside a JavaScript loop, with practical examples and best practices. Approaches to Create Dynamic Variable Names Here are the four main approaches we'll cover, each with different use cases and considerations: Using Array Using eval() ...

Read More

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

Amit Sharma
Amit Sharma
Updated on 15-Mar-2026 152 Views

JavaScript variables declared with var are dynamically typed, meaning they can store any type of data and their type can change during execution. The variable itself doesn't have a fixed type, but the value it holds does. Dynamic Typing in JavaScript Unlike statically typed languages, JavaScript allows the same variable to hold different data types throughout its lifetime. This flexibility is both powerful and requires careful handling. Example: Variable Type Changes var a; ...

Read More

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

Nikitasha Shrivastava
Nikitasha Shrivastava
Updated on 15-Mar-2026 2K+ Views

When learning different programming languages, you may come across terms like untyped and dynamically typed. While they may sound similar, they represent different concepts in how programming languages manage data types. In this article, we will explore these concepts with clear examples and comparisons. What is an Untyped Language? Untyped programming languages do not have strict data type definitions. Variables can hold any type of value without explicit type declarations, and the language treats all data as a uniform type internally. Example of Untyped Behavior JavaScript demonstrates untyped characteristics where variables can hold any value: ...

Read More

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

Amit Sharma
Amit Sharma
Updated on 15-Mar-2026 198 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. Dynamic Typing Example ...

Read More

How are variables allocated memory in JavaScript?

Sai Subramanyam
Sai Subramanyam
Updated on 15-Mar-2026 462 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 ...

Read More
Showing 19141–19150 of 61,297 articles
Advertisements