Javascript Articles

Page 444 of 534

How to set JavaScript object values dynamically?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 803 Views

JavaScript objects allow dynamic property assignment using bracket notation or dot notation. This enables you to set object values at runtime based on variables or user input. Syntax // Using dot notation object.propertyName = value; // Using bracket notation (dynamic) object[propertyName] = value; object['property name'] = value; Method 1: Using Dot Notation Dot notation works when you know the property name at compile time: Dynamic Object Values body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; ...

Read More

Modifying prototypes in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 224 Views

In JavaScript, prototypes allow you to add properties and methods to constructor functions. You can modify prototypes even after objects are created, and all existing instances will automatically inherit the changes. Understanding Prototypes Every function in JavaScript has a prototype property. When you create objects using a constructor function, they inherit methods and properties from the constructor's prototype. Example: Modifying Prototypes Modifying Prototypes body { ...

Read More

Conditional statements in JavaScript

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

Conditional statements allow you to execute different blocks of code based on specific conditions. JavaScript provides three main types of conditional statements to control program flow. Types of Conditional Statements if statement − Executes code only if a specific condition is true. if...else statement − Checks one condition and executes different code blocks for true and false cases. if...else if...else statement − Handles multiple conditions by checking them sequentially. Syntax // if statement if (condition) { // code to execute ...

Read More

Indexed collections in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 4K+ Views

JavaScript provides indexed collections that allow you to store and access elements using numeric indices. Arrays are the most common indexed collection, where each element has a position (index) starting from 0. What are Indexed Collections? Indexed collections are data structures where elements are accessed using numerical indices. In JavaScript, arrays are the primary indexed collection type, allowing you to store multiple values and retrieve them using their position. Basic Array Creation and Access Indexed Collections ...

Read More

Keyed collections in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 711 Views

Keyed collections are data structures in JavaScript where elements are organized by keys rather than indices. The two main keyed collections are Map and Set objects, which maintain insertion order and provide efficient key-based operations. Map Collection A Map object holds key-value pairs and remembers the original insertion order of the keys. Unlike objects, Map keys can be of any type. Map Collection Example Map Collection Demo ...

Read More

Loading JavaScript modules dynamically

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 245 Views

Dynamic module loading allows you to import JavaScript modules at runtime rather than at compile time. This enables lazy loading, conditional imports, and better performance optimization. Static vs Dynamic Import Static imports happen at the top of files and load immediately. Dynamic imports use the import() function to load modules on demand. Dynamic Module Loading body { ...

Read More

Renaming imports and exports in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 243 Views

JavaScript ES6 modules allow you to rename imports and exports using the as keyword. This is useful for avoiding naming conflicts, improving code readability, or providing more descriptive names for functions and variables. Note − You need to run a localhost server to run this example due to ES6 module requirements. Syntax For renaming exports: export { originalName as newName }; For renaming imports: import { originalName as newName } from './module.js'; Example Let's create a complete example with three files demonstrating both import and export renaming: ...

Read More

loose equality in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 300 Views

The loose equality operator == compares two values after performing type coercion, converting them to a common type before comparison. This differs from strict equality (===) which compares both value and type. Syntax operand1 == operand2 How Loose Equality Works When using ==, JavaScript follows specific conversion rules: If types are the same, compare values directly If one is a number and the other a string, convert string to number If one is boolean, convert to number first null and undefined are equal to each other Example ...

Read More

Strict equality vs Loose equality in JavaScript.

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

In JavaScript, there are two ways to compare values for equality: loose equality (==) and strict equality (===). Understanding the difference is crucial for writing reliable code. Loose Equality (==) The loose equality operator == compares values after converting them to a common type (type coercion). This can lead to unexpected results. Loose Equality Examples Loose Equality Results ...

Read More

Accessing an array returned by a function in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 869 Views

In JavaScript, functions can return arrays that can be accessed and manipulated directly. This is useful for creating reusable code that generates data structures. Basic Syntax function functionName() { let array = [/* elements */]; return array; } // Access the returned array let result = functionName(); Example: Returning and Accessing Arrays Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; ...

Read More
Showing 4431–4440 of 5,340 articles
« Prev 1 442 443 444 445 446 534 Next »
Advertisements