Articles on Trending Technologies

Technical articles with clear explanations and examples

How to use 'const' keyword in JavaScript?

Abhishek Kumar
Abhishek Kumar
Updated on 15-Mar-2026 3K+ Views

We use the const keyword in JavaScript to declare variables whose value can be initialized only at the time of declaration. It is similar functionality of declaring variables as the other keywords provided in JavaScript i.e. var and let. const is short for constant, meaning that the value that resides in the variable is unchangeable. The const keyword in JavaScript It is used to declare variables in JavaScript. The variables created using const follow certain rules. The variable is block scoped. This means that the scope(lifetime) of the variable depends on the place ...

Read More

Why is 'class' a reserved word in JavaScript?

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

The class keyword is a reserved word in JavaScript because it was designated as a "future reserved word" in ECMAScript 5 and later implemented in ECMAScript 6 (ES2015) to introduce class-based object-oriented programming. Future Reserved Words in ECMAScript 5 ECMAScript 5 specification defined several future reserved words to allow for possible language extensions: class enum extends super const export import These words were reserved in ECMAScript 5 even though they had no functionality yet, ensuring they would be available for future language features without breaking existing code. Implementation in ECMAScript 6 In ...

Read More

Why JavaScript 'var null' throw an error but 'var undefined' doesn't?

Johar Ali
Johar Ali
Updated on 15-Mar-2026 245 Views

In JavaScript, var null throws a syntax error because null is a reserved keyword, while var undefined works because undefined is not a reserved identifier. Reserved Keywords in JavaScript JavaScript has reserved keywords that cannot be used as variable names. These include: null true false if for while function var let const Why 'var null' Throws an Error When you try to declare a variable named null, JavaScript throws a syntax error: // This will throw a SyntaxError var null = "some value"; SyntaxError: Unexpected token 'null' ...

Read More

What are Variable Naming Conventions in JavaScript

Ali
Ali
Updated on 15-Mar-2026 1K+ Views

While naming your variables in JavaScript, keep some rules in mind. The following are the variable naming conventions in JavaScript: You should not use any of the JavaScript reserved keywords as a variable name. These keywords are mentioned in the next section. For example, break or boolean variable names are not valid. JavaScript variable names should not start with a numeral (0-9). They must begin with a letter or an underscore character. For example, 123test is an invalid variable name but _123test is a valid one. JavaScript variable names ...

Read More

How to name variables in JavaScript?

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

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. While naming your variables in JavaScript, keep the following rules in mind. Variable Naming Rules You should not use any of the JavaScript reserved keywords as a variable name. These keywords are mentioned in the next section. For example, break or boolean variable names are not valid. JavaScript variable names should not start with a numeral (0-9). They must begin with a letter or an underscore character. For example, 123test ...

Read More

How to replace all occurrences of a string in JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 11K+ Views

In JavaScript, there are several methods to replace all occurrences of a substring within a string. This tutorial covers three effective approaches: using split() and join(), regular expressions with replace(), and the modern replaceAll() method. Using split() and join() This method splits the string at each occurrence of the target substring, then joins the parts back together with the replacement string. Syntax const given_string = "original string"; const to_replace = "substring to find"; const replacement = "replacement string"; const string_after_splitting = given_string.split(to_replace); const required_string = string_after_splitting.join(replacement); Example ...

Read More

How is JavaScript an untyped language?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 1K+ Views

JavaScript is an untyped (or dynamically typed) language because variables can hold any data type without explicit type declaration. Unlike statically typed languages like Java, C#, C++ that require type declarations like int, char, float, JavaScript uses var, let, and const to create variables of any type. One of the key advantages of untyped languages is the flexibility to reassign different data types to the same variable during runtime. Dynamic Type Assignment In this example, we create a variable named "x" and assign different data types to it. At each step, we print the type of the ...

Read More

What happens when you do not declare a variable in JavaScript?

Ali
Ali
Updated on 15-Mar-2026 304 Views

When you don't declare a variable in JavaScript using var, let, or const, JavaScript automatically creates it as a global variable. This behavior can lead to unexpected results and is generally considered bad practice. How Undeclared Variables Work When you assign a value to an undeclared variable, JavaScript creates it in the global scope, even if you're inside a function. This happens because JavaScript searches the scope chain for the variable, and if not found, creates it globally. Example: Undeclared vs Declared Variables ...

Read More

Variable Hoisting in JavaScript

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

When you can use a JavaScript variable before it is declared, it is done using a technique called hoisting. The parser reads through the complete function before running it. The behavior in which a variable appears to be used before it is declared is known as hoisting. JavaScript moves variable declarations to the top of their scope during compilation. Example: var Hoisting For example, the following code works due to hoisting: points = 200; var points; console.log(points); 200 The above works the same as if you had written: ...

Read More

What happens if we re-declare a variable in JavaScript?

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

When you re-declare a variable in JavaScript using var, the original value is preserved. The re-declaration doesn't reset or change the variable's value. Example Let's see an example where we declare the variable age twice: Variable Re-declaration Example var age = 20; var age; // Re-declaration without assignment ...

Read More
Showing 19151–19160 of 61,297 articles
Advertisements