Javascript Articles

Page 514 of 534

How to pass the value 'undefined' to a function with multiple parameters in JavaScript?

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

In this tutorial, we will learn how to pass the value 'undefined' to a function with multiple parameters in JavaScript. In JavaScript, the data type of 'undefined' is primitive. When a variable is declared, JavaScript automatically assigns the value 'undefined' to it. If a function has multiple parameters and one of the parameters' values is not available at the moment, then we need to omit that parameter's value from the function call. But if we omit the parameter's value with a blank space, the JavaScript will show an error. The Problem function abc(param1, param2, param3) { ...

Read More

How to use a line break in array values in JavaScript?

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

We use the join() method of JavaScript to use a line break in array values. It allows us to concatenate all the constituent elements of an array into a single string using a common separator. The join() method in JavaScript The join() method takes as input a single separator string and returns a string with all the elements of the array separated by the specified separator string. The separator string by default is the comma(, ). The join method uses the toString() method to convert the elements of the array into corresponding strings. A null or undefined ...

Read More

What is lexical this in JavaScript?

Sreemaha
Sreemaha
Updated on 15-Mar-2026 2K+ Views

In JavaScript, "lexical this" refers to how arrow functions inherit the this context from their enclosing scope, unlike regular functions that define their own this. This solves common issues with this binding in callbacks and nested functions. The Problem with Regular Functions Regular functions create their own this context, which can lead to unexpected behavior in callbacks: Click Me document.getElementById('myButton').addEventListener('click', function() { console.log('Outer this:', this); // Points to the button setTimeout(function() { console.log('Inner ...

Read More

What is a fat arrow function in JavaScript?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 723 Views

Fat arrow functions (also called arrow functions) were introduced in ES6 to provide a shorter syntax for writing functions. They use the => syntax, which resembles a "fat arrow", eliminating the need to write the function keyword repeatedly. Syntax For a single argument: argument => expression For multiple arguments or no arguments: (argument1, argument2) => expression // or () => expression Example: Traditional vs Arrow Function Traditional Function: var rank = [7, 8, 9]; var display = rank.map(function(num) { return num * num; ...

Read More

Why avoid increment ("++") and decrement ("--") operators in JavaScript?

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

The increment (++) and decrement (--) operators in JavaScript can lead to confusing code and unexpected results due to their pre-increment and post-increment behavior. Understanding why they should be avoided helps write clearer, more maintainable code. Pre-increment vs Post-increment Confusion The main issue with increment operators is the difference between pre-increment (++a) and post-increment (a++), which can produce unexpected values in assignments: var a = 5; var b = ++a; // Pre-increment: a becomes ...

Read More

What is decrement (--) operator in JavaScript?

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 757 Views

The decrement operator in JavaScript decreases an integer value by one. This operator is often utilized in loops, counters, and mathematical computations where a value has to be decreased sequentially. Types of Decrement Operators The decrement operator (--) can be used in two ways: Post-decrement (x--): Returns the current value of the variable first, then decrements it. Pre-decrement (--x): Decrements the value first, then returns the new value. Syntax x--; // Post-decrement --x; // Pre-decrement Pre-decrement Example Pre-decrement decreases the value ...

Read More

What is increment (++) operator in JavaScript?

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

The increment operator (++) increases a numeric value by one. It comes in two forms: pre-increment (++variable) and post-increment (variable++), which behave differently in expressions. Syntax ++variable // Pre-increment: increment first, then return value variable++ // Post-increment: return value first, then increment Pre-increment vs Post-increment let a = 5; let b = 5; ...

Read More

Can I declare JavaScript variables as specific types?

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

In this tutorial, we will explore whether JavaScript variables can be declared with specific types. JavaScript contains three reserved keywords to declare variables: let, var, and const. When declaring variables, each keyword has different scope behavior. Variables declared with const remain constant and cannot be reassigned after initialization. Variables declared with let have block scope and cannot be accessed outside their scope. Variables declared with var can have global or function scope. Syntax let var1 = value; var var2 = value; const var3 = value; JavaScript is dynamically typed, meaning you don't need to ...

Read More

How do I empty an array in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 645 Views

This tutorial teaches us to make an array empty in JavaScript. While programming with JavaScript, programmers need to make an array empty in many conditions. For example, coders are doing competitive programming with JavaScript. Suppose, to solve some problem, they need to create a new or an empty array while calling the function every time. Users can visualize this problem from the below example. function child() { // create a new array or use a single array and make it empty every time function invokes } function parent() { ...

Read More

How can I check whether a variable is defined in JavaScript?

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

In JavaScript, checking whether a variable is defined helps prevent ReferenceError exceptions. A variable can be declared but undefined, declared and defined, or completely undeclared. Understanding the difference between these states is crucial: const data = 10; // declared and defined (initialized with value 10) let data; // declared but undefined const data = null; // declared and defined (initialized with null) data = 10; // undeclared but assigned (creates global variable) data ...

Read More
Showing 5131–5140 of 5,340 articles
« Prev 1 512 513 514 515 516 534 Next »
Advertisements