Web Development Articles

Page 425 of 801

JavaScript Numbers example

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 197 Views

JavaScript has a single number type that represents both integers and floating-point numbers. Unlike other languages, JavaScript doesn't distinguish between different numeric types. Number Types in JavaScript All numbers in JavaScript are stored as 64-bit floating-point values, following the IEEE 754 standard. This means you can work with both whole numbers and decimals seamlessly. JavaScript Numbers body { ...

Read More

JavaScript Promises

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

Promises in JavaScript allow us to handle asynchronous operations where the value is not known in advance when the promise is being created. A promise can have three states: pending, fulfilled, and rejected. Promise States A promise represents an asynchronous operation and can be in one of three states: Pending: Initial state, neither fulfilled nor rejected Fulfilled: The operation completed successfully Rejected: The operation failed Creating a Basic Promise Here's how to create a simple promise: ...

Read More

JavaScript undefined Property

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 248 Views

The JavaScript undefined property represents a value that indicates a variable has been declared but not assigned a value, or a property that doesn't exist. What is undefined? undefined is a primitive value automatically assigned to variables that are declared but not initialized, and to object properties that don't exist. Common Cases Where undefined Occurs // Declared but not assigned let age; console.log(age); // undefined // Function with no return value function greet() { console.log("Hello"); } let result = greet(); console.log(result); // undefined // Accessing non-existent object property let ...

Read More

Finding matches in two elements JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 260 Views

We are required to write a function that returns true if the string in the first element of the array contains all of the letters of the string in the second element of the array. For example: ["hello", "Hello"], should return true because all of the letters in the second string are present in the first, ignoring their case. The arguments ["hello", "hey"] should return false because the string "hello" does not contain a "y". Lastly, ["Alien", "line"], should return true because all of the letters in "line" are present in "Alien". This ...

Read More

JavaScript unescape() with example

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 305 Views

The JavaScript unescape() function is used to decode strings that were encoded with the escape() function. This function is deprecated since JavaScript 1.5 and should not be used in modern code. Use decodeURIComponent() instead. Syntax unescape(encodedString) Parameter: encodedString - The string to be decoded. Return Value: A new decoded string. Example with unescape() (Deprecated) JavaScript unescape() Example body { ...

Read More

Return the maximum number in each array using map JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 796 Views

We have an array of arrays of Numbers like this one: const arr = [ [12, 56, 34, 88], [65, 66, 32, 98], [43, 87, 65, 43], [32, 98, 76, 83], [65, 89, 32, 54], ]; We are required to write a function that maps over this array of arrays and returns an array that contains the maximum (greatest) element from each subarray. Using Math.max() with Spread Operator The most straightforward approach is to use Math.max() with the spread operator to find the maximum ...

Read More

JavaScript WebAPI File File.name Property

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 143 Views

The JavaScript File WebAPI file.name property returns only the name of the file without the path. This property is read-only and provides access to the filename when working with file inputs or drag-and-drop operations. Syntax file.name Return Value Returns a string containing the name of the file without any path information. The name includes the file extension if present. Example File.name Property Example ...

Read More

How to create an ordered array from values that have an order number in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 207 Views

When working with arrays containing values and order numbers, you often need to sort them by their order and extract just the values. This is common when dealing with image galleries, menu items, or any data that needs custom ordering. Problem Setup Let's say we have an array of strings where each string contains a file path and an order number separated by a comma: const images = [ 'photo1.jpg, 0', 'photo2.jpg, 2', 'photo3.jpg, 1' ]; console.log("Original array:", images); Original array: [ 'photo1.jpg, 0', 'photo2.jpg, ...

Read More

JavaScript to generate random hex codes of color

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 345 Views

Generating random hex color codes in JavaScript involves creating a 6-character string from hexadecimal digits (0-9, A-F) and prefixing it with '#'. This is useful for creating dynamic color schemes, themes, or visual effects. Understanding Hex Color Codes Hex color codes use the format #RRGGBB where each pair represents red, green, and blue values in hexadecimal (0-F). For example, #FF0000 is pure red, #00FF00 is green, and #0000FF is blue. Method 1: Using Math.random() with Character Selection Random Hex Color Generator ...

Read More

JavaScript Importing and Exporting Modules

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 350 Views

JavaScript modules allow you to split code into separate files and share functionality between them using import and export statements. This promotes code reusability and better organization. Note: To run module examples, you need a localhost server since modules use CORS policy. Export Types There are two main ways to export from a module: Default Export: One main export per module Named Export: Multiple exports with specific names Default Export Example math.js (module file): // Default export - only one per module export default function add(a, b) { ...

Read More
Showing 4241–4250 of 8,010 articles
« Prev 1 423 424 425 426 427 801 Next »
Advertisements