Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Javascript Articles
Page 444 of 534
How to set JavaScript object values dynamically?
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 MoreModifying prototypes in JavaScript
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 MoreConditional statements in JavaScript
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 MoreIndexed collections in JavaScript
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 MoreKeyed collections in JavaScript
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 MoreLoading JavaScript modules dynamically
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 MoreRenaming imports and exports in JavaScript
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 Moreloose equality in JavaScript
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 MoreStrict equality vs Loose equality in JavaScript.
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 MoreAccessing an array returned by a function in JavaScript
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