Javascript Articles

Page 426 of 534

JavaScript undefined Property

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 232 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

JavaScript unescape() with example

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 293 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

JavaScript WebAPI File File.name Property

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 135 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

JavaScript to generate random hex codes of color

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 325 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 345 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

How to create a countdown timer with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 736 Views

A countdown timer in JavaScript uses setInterval() to update the display every second by calculating the time difference between a target date and the current time. How It Works The countdown timer works by: Setting a target date in the future Calculating the time difference every second Converting milliseconds to days, hours, minutes, and seconds Updating the display and stopping when time expires Complete Example body { ...

Read More

How to create a typing effect with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 337 Views

To create a typing effect with JavaScript, you can simulate the appearance of text being typed character by character. This effect is commonly used for animated headers, loading messages, or interactive demonstrations. Basic Typing Effect Here's a complete example that demonstrates how to create a typing effect: body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; padding: 20px; } button { padding: 10px 20px; ...

Read More

How to close list items with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 644 Views

Closing list items with JavaScript involves adding click event listeners to close buttons that hide or remove list items from the DOM. This creates an interactive list where users can dismiss items they no longer need. Complete Example body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } * { ...

Read More

How to create a draggable HTML element with JavaScript and CSS?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 727 Views

To create a draggable HTML element with JavaScript and CSS, you need to handle mouse events and update the element's position dynamically. This technique allows users to click and drag elements around the page. Basic HTML Structure Start with an HTML element that has absolute positioning and a move cursor to indicate it's draggable: body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .dragDiv { position: absolute; ...

Read More

How to use media queries with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 396 Views

JavaScript provides the window.matchMedia() method to detect and respond to CSS media query changes dynamically. This allows you to create responsive behavior that adapts to screen size, device orientation, and other media features. Basic Syntax let mediaQuery = window.matchMedia("(max-width: 768px)"); // Check if query matches if (mediaQuery.matches) { // Screen is 768px or smaller } // Listen for changes mediaQuery.addEventListener('change', function(e) { if (e.matches) { // Query now matches } }); Example: Responsive ...

Read More
Showing 4251–4260 of 5,340 articles
« Prev 1 424 425 426 427 428 534 Next »
Advertisements