Javascript Articles

Page 439 of 534

What's the best way to open new browser window using JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 302 Views

The window.open() method is the standard way to open new browser windows in JavaScript. It provides control over window features and behavior. Syntax window.open(url, name, features) Parameters url: The URL to open (optional) name: Window name or target (optional) features: Window features like size, position, toolbar (optional) Basic Example Open New Window body { ...

Read More

JavaScript to parse and show current time stamp of an HTML audio player.

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

The HTML audio element provides a currentTime property that returns the current playback position in seconds. We can parse this value to display minutes and seconds separately. HTML Audio currentTime Property The currentTime property returns a floating-point number representing the current playback time in seconds. We can use Math.floor() to convert it into readable minutes and seconds format. Example Audio Timestamp Parser body { ...

Read More

Lambdas with Arrow Functions in JavaScriptLambdas with Arrow Functions in JavaScript

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

Lambda functions in JavaScript are small anonymous functions that can take parameters and return values. Arrow functions provide a concise way to write lambda functions and are commonly used for functional programming operations like map(), filter(), and reduce(). Syntax // Single parameter (parentheses optional) const lambda1 = x => x * 2; // Multiple parameters const lambda2 = (x, y) => x + y; // No parameters const lambda3 = () => "Hello World"; // Multiple statements (requires curly braces and return) const lambda4 = x => { const result ...

Read More

How to read data from JSON array using JavaScript?

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

JSON arrays are a common data structure in JavaScript applications. This article demonstrates various methods to read and access data from JSON arrays. What is a JSON Array? A JSON array is a collection of JSON objects enclosed in square brackets. Each object can contain multiple key-value pairs. [ {"name": "Rohan", "age": 22}, {"name": "Shawn", "age": 12}, {"name": "Michael", "age": 21} ] Method 1: Using JSON.parse() and forEach() The most common approach is parsing the JSON string and iterating through the array: ...

Read More

Effective Function Signatures with Default and Rest Parameters in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 159 Views

JavaScript function signatures with default and rest parameters allow you to create flexible functions that handle variable arguments and provide fallback values when parameters are missing. Default Parameters Default parameters provide fallback values when arguments are undefined or not passed: Default Parameters function greet(name = "Guest", greeting = "Hello") { return `${greeting}, ...

Read More

How to import an Object with Sub Objects and Arrays in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 629 Views

Importing objects with nested sub-objects and arrays in JavaScript using ES6 modules allows for modular code organization. This technique is essential for sharing complex data structures between different JavaScript files. What are ES6 Modules? ES6 modules use export and import statements to share code between files. The export default syntax allows exporting a single object, function, or value as the default export from a module. Example: Importing Complex Objects Let's create a complete example showing how to import an object containing nested objects and arrays. sample.js (Module file) export default { ...

Read More

Formatted Strings Using Template Strings in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 330 Views

Template strings (template literals) in JavaScript allow you to create formatted strings with embedded expressions using backticks (`). They provide a cleaner alternative to string concatenation and offer multiline support. Syntax `string text ${expression} string text` Basic Example Template Strings Example Template String Formatting Show Formatted String ...

Read More

When you should not use JavaScript Arrow Functions?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 218 Views

Arrow functions should not be used in certain scenarios because they don't have their own this binding. Instead, they inherit this from the enclosing lexical scope, which can lead to unexpected behavior. When NOT to Use Arrow Functions Object Methods Arrow functions should not be used as object methods because they don't bind this to the object. Instead, this refers to the global scope (window in browsers). Arrow Functions - Object Methods Arrow Function vs Regular Function in Objects ...

Read More

Using '{ }' in JavaScript imports?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 197 Views

In JavaScript ES6 modules, curly braces { } are used for named imports, allowing you to import specific exported functions, variables, or classes from a module. Syntax // Named imports import { functionName, variableName } from './module.js'; // Named imports with alias import { originalName as newName } from './module.js'; // Mixed import import defaultExport, { namedExport } from './module.js'; Example JavaScript Named Imports ...

Read More

Implement Private properties using closures in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 189 Views

In JavaScript, closures provide a powerful way to create private properties that cannot be accessed directly from outside a function. This technique encapsulates data and prevents external code from modifying internal variables. What are Private Properties? Private properties are variables that can only be accessed and modified through specific methods, not directly from outside the containing scope. Closures enable this by keeping variables alive in memory even after the outer function has finished executing. How Closures Create Privacy When an inner function references variables from its outer function, it forms a closure. The outer function's variables ...

Read More
Showing 4381–4390 of 5,340 articles
« Prev 1 437 438 439 440 441 534 Next »
Advertisements