HTML Articles

Page 123 of 151

What will happen if a semicolon is misplaced in JavaScript?

Srinivas Gorla
Srinivas Gorla
Updated on 15-Mar-2026 259 Views

If a semicolon is misplaced in JavaScript, it can lead to unexpected behavior due to Automatic Semicolon Insertion (ASI). JavaScript automatically inserts semicolons at the end of statements, which can sometimes cause logical errors when semicolons are placed incorrectly. Common Semicolon Misplacement Issues The most common problem occurs when a semicolon is accidentally placed after control flow statements like if, for, or while. Example: Semicolon After if Statement var val1 = 10; ...

Read More

With JavaScript RegExp search a hexadecimal number character.

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 466 Views

To find a hexadecimal number character with JavaScript Regular Expression, use the \x escape sequence followed by the two-digit hexadecimal value. Syntax \xdd Where dd represents the two-digit hexadecimal value (00-FF) of the character you want to match. Example: Searching for Hexadecimal Character The following example searches for hexadecimal number 53, which represents the character 'S': JavaScript Regular Expression ...

Read More

How to return a random number between 0 and 199 with JavaScript?

Rama Giri
Rama Giri
Updated on 15-Mar-2026 455 Views

To return a random number between 0 and 199, use the JavaScript Math.random() and Math.floor() methods together. How It Works Math.random() generates a random decimal between 0 (inclusive) and 1 (exclusive). To get integers from 0 to 199: Multiply by 200 to get range 0 to 199.999... Use Math.floor() to round down to nearest integer Example // Generate random number between 0-199 let randomNum = Math.floor(Math.random() * ...

Read More

How to return the "time" portion of the Date as a string using the current locale's conventions?

Priya Pallavi
Priya Pallavi
Updated on 15-Mar-2026 156 Views

To return the "time" portion of the Date as a string, using the current locale's conventions, use the toLocaleTimeString() method. The toLocaleTimeString() method relies on the underlying operating system in formatting dates. It converts the date to a string using the formatting convention of the operating system where the script is running. For example, in the United States, the time appears in 12-hour format with AM/PM, whereas in many European countries, it appears in 24-hour format. Syntax date.toLocaleTimeString([locales], [options]) Parameters locales (optional): A string or array of strings representing locale identifiers (e.g., ...

Read More

What is the usage of onpageshow event in JavaScript?

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 244 Views

The onpageshow event triggers in JavaScript when a user navigates to a web page, including when the page loads for the first time or when returning from the browser's back/forward cache (bfcache). Syntax // HTML attribute // Event listener window.addEventListener('pageshow', function(event) { // Handle page show }); Example: Basic Usage Here's how to implement the onpageshow event using HTML attribute: On first visit, a welcome message is visible. ...

Read More

How to return a string representing the source for an equivalent Date object?

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 146 Views

The toSource() method was a non-standard JavaScript method that returned a string representing the source code of a Date object. However, this method has been deprecated and removed from modern browsers. The Deprecated toSource() Method The toSource() method was originally available in Firefox but was never part of the ECMAScript standard. It would return a string that could theoretically recreate the Date object: // This method is deprecated and no longer works var dt = new Date(2018, 0, 15, 14, 39, 7); // dt.toSource() would have returned: (new Date(1516022347000)) Modern Alternatives Since toSource() ...

Read More

What is the usage of onpagehide event in JavaScript?

Akshaya Akki
Akshaya Akki
Updated on 15-Mar-2026 508 Views

The onpagehide event triggers in JavaScript when a user leaves the page and navigates away. This occurs during page refresh, clicking links, closing the browser tab, or navigating to another page. Syntax // HTML attribute // JavaScript event listener window.addEventListener('pagehide', function(event) { // Code to execute }); Example: Basic Usage Here's how to implement the onpagehide event using an HTML attribute: Navigate away from this page to see the alert! ...

Read More

How to apply a function simultaneously against two values of the array from left-to-right?

Manikanth Mani
Manikanth Mani
Updated on 15-Mar-2026 233 Views

The reduce() current) ? prev : current; }); document.write("Maximum value: " + max + ""); // Count occurrences var fruits = ['apple', 'banana', 'apple', 'orange', 'banana', 'apple']; var count = fruits.reduce(function(acc, fruit) { ...

Read More

How to add properties and methods to an object in JavaScript?

V Jyothi
V Jyothi
Updated on 15-Mar-2026 310 Views

In JavaScript, you can add properties and methods to objects using several approaches. The most common methods include direct assignment, using the prototype property for constructor functions, and using Object.defineProperty(). Method 1: Direct Property Assignment The simplest way to add properties to an existing object is direct assignment: Direct Property Assignment let car = { brand: "Toyota", ...

Read More

How to convert Boolean to Number in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 5K+ Views

In JavaScript, Boolean values (true and false) can be converted to numbers (1 and 0 respectively) using several methods. This conversion is useful when performing mathematical operations or comparisons that require numeric values. JavaScript provides multiple approaches to convert Boolean values to numbers. Let's explore three effective methods with examples. Using the Number() Function The Number() function is the most explicit and readable way to convert Boolean values to numbers. It converts true to 1 and false to 0. Syntax let result = Number(booleanValue); Example ...

Read More
Showing 1221–1230 of 1,509 articles
« Prev 1 121 122 123 124 125 151 Next »
Advertisements