Javascript Articles

Page 433 of 534

Explain touch events in JavaScript

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

Touch events in JavaScript are fired when a user interacts with a touchscreen device. These events provide a way to handle touch-based interactions on mobile devices, tablets, and other touch-enabled screens. Touch Event Types JavaScript provides four main touch events for handling different stages of touch interaction: Event Description ...

Read More

Explain load events in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 841 Views

Load events in JavaScript are fired at different stages of the page lifecycle, from initial DOM construction to complete resource loading and page unloading. Understanding these events helps you execute code at the right time. Types of Load Events Event Description When It Fires DOMContentLoaded DOM tree is built but external resources like stylesheets and images are still loading HTML parsed completely load All resources (images, stylesheets, scripts) are fully loaded Page completely loaded beforeunload User is about to leave the page - can show confirmation dialog ...

Read More

Disabling arrow key in text area using JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 365 Views

You can disable arrow key navigation in a text area using JavaScript by intercepting keydown events and preventing their default behavior. This technique is useful when you want to restrict user interaction or create custom navigation controls. Understanding Arrow Key Codes Arrow keys have specific key codes that we can detect: Left Arrow: 37 Up Arrow: 38 Right Arrow: 39 Down Arrow: 40 Complete Example Disable Arrow Keys in Textarea ...

Read More

Validating a file size in JavaScript while uploading

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

File size validation is essential for web applications to prevent users from uploading files that are too large for your server or application limits. JavaScript provides built-in methods to check file size before upload begins. How File Size Validation Works When a user selects a file using an HTML file input, JavaScript can access the file's properties through the files property. The size property returns the file size in bytes, which we can then validate against our requirements. Basic File Size Validation ...

Read More

Undeclared vs Undefined? In JavaScript

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

In JavaScript, undeclared and undefined are two different concepts that developers often confuse. Understanding the distinction is crucial for debugging and writing reliable code. Key Differences Undeclared occurs when you try to access a variable that hasn't been declared using var, let, or const. This results in a ReferenceError. Undefined occurs when a variable has been declared but hasn't been assigned a value. The variable exists but contains the special value undefined. Example: Undefined Variable Undefined Variable ...

Read More

innerHTML vs innerText in JavaScript.

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

The innerHTML and innerText properties are two different ways to access and manipulate the content of HTML elements in JavaScript. innerHTML - Returns or sets the HTML markup inside an element, including all tags, formatting, and spacing. It preserves the complete HTML structure. innerText - Returns or sets only the visible text content, stripping out all HTML tags and normalizing whitespace. Key Differences Property HTML Tags Whitespace Hidden Elements innerHTML Preserved Preserved Included innerText Removed Normalized Excluded Example ...

Read More

How do JavaScript primitive/object types passed in functions?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 277 Views

In JavaScript, understanding how data types are passed to functions is crucial. Primitive types are passed by value, while objects are passed by reference. This affects how modifications inside functions impact the original data. Pass by Value (Primitives) Primitive types (string, number, boolean, null, undefined, symbol, bigint) are passed by value. A copy is made, so changes inside the function don't affect the original variable. Pass by Value Example function modifyPrimitive(value) { value = value + 10; document.getElementById('output').innerHTML += ...

Read More

Escape characters in JavaScript

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

Escape characters are special characters that require a backslash (\) prefix to be displayed literally in JavaScript strings. Without escaping, these characters have special meanings that could break your code or produce unexpected results. Common Escape Characters Code Result Description ' Single quote Allows single quotes inside single-quoted strings " Double quote Allows double quotes inside double-quoted strings \ Backslash Displays a literal backslash character New Line Creates a line break \t Tab Creates horizontal spacing \r Carriage Return Returns ...

Read More

How to borrow methods in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 215 Views

Method borrowing allows an object to use another object's method by temporarily setting the context using call(), apply(), or bind(). Understanding Method Borrowing In JavaScript, methods are just functions attached to objects. When you borrow a method, you're calling a function from one object but executing it in the context of another object using this binding. Using call() Method The call() method invokes a function with a specified this context and individual arguments. Method Borrowing with call() ...

Read More

Passing empty parameter to a method in JavaScript

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

In JavaScript, you can pass empty parameters to a method by simply omitting them when calling the function. This is useful when working with functions that have default parameters or when you want to rely on the function's default behavior. Understanding Default Parameters Default parameters allow functions to have fallback values when no arguments are provided or when undefined is passed. Passing Empty Parameters body { ...

Read More
Showing 4321–4330 of 5,340 articles
« Prev 1 431 432 433 434 435 534 Next »
Advertisements