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 426 of 534
JavaScript undefined Property
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 MoreJavaScript unescape() with example
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 MoreJavaScript WebAPI File File.name Property
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 MoreJavaScript to generate random hex codes of color
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 MoreJavaScript Importing and Exporting Modules
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 MoreHow to create a countdown timer with JavaScript?
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 MoreHow to create a typing effect with JavaScript?
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 MoreHow to close list items with JavaScript?
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 MoreHow to create a draggable HTML element with JavaScript and CSS?
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 MoreHow to use media queries with JavaScript?
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