Programming Scripts Articles

Page 6 of 33

What will happen if a semicolon is misplaced in JavaScript?

Srinivas Gorla
Srinivas Gorla
Updated on 15-Mar-2026 268 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

How to check whether a value is a safe integer or not in JavaScript?

Shubham Vora
Shubham Vora
Updated on 15-Mar-2026 709 Views

In this tutorial, we will learn to check whether a value is a safe integer or not in JavaScript. A safe integer in JavaScript is any number that can be accurately represented under the IEEE-754 double-precision format. Safe integers are all numbers between -(2^53 - 1) and (2^53 - 1) inclusive. JavaScript provides a built-in method for this check, but we can also implement custom logic. Here are the approaches we'll explore: Using the Number.isSafeInteger() Method (Recommended) Using Custom if-else Logic Using Number.isSafeInteger() Method The Number.isSafeInteger() ...

Read More

How to convert Unicode values to characters in JavaScript?

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

In this tutorial, we will learn to convert Unicode values to characters in JavaScript. The Unicode values are the standard values for the character, and users can encode them to convert them into characters. For example, 'A' is a Unicode character whose value is 65 according to the ASCII (American standard code for information interchange) table. In the same way, all alphabets, numbers, and other characters have particular Unicode values. We will learn to identify the Unicode character from its values using JavaScript. Using the fromCharCode() Method In JavaScript, the String object contains the fromCharCode() method, which ...

Read More

For Hosts Locale how to convert a string to lowercase letters in JavaScript?

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 15-Mar-2026 215 Views

To convert a string to lowercase letters in JavaScript, use the toLocaleLowerCase() method. This method converts characters to lowercase according to the host's locale, making it ideal for international applications. Syntax string.toLocaleLowerCase([locale]) Parameters locale (optional): A string specifying the locale to use for conversion. If omitted, the host environment's current locale is used. Basic Example Here's how to use toLocaleLowerCase() to convert a string to lowercase: var str ...

Read More

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

Rama Giri
Rama Giri
Updated on 15-Mar-2026 464 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

What is the role of pageXOffset property in JavaScript?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 307 Views

The pageXOffset property returns the number of pixels the document has been scrolled horizontally from the left edge of the window. It's a read-only property of the window object used to track horizontal scroll position. Syntax let horizontalScroll = window.pageXOffset; Return Value Returns a number representing the horizontal scroll position in pixels. Returns 0 if the document hasn't been scrolled horizontally. Example: Basic Usage div { ...

Read More

What is the usage of onpageshow event in JavaScript?

Nitya Raut
Nitya Raut
Updated on 15-Mar-2026 249 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

With JavaScript RegExp search a hexadecimal number character.

Smita Kapse
Smita Kapse
Updated on 15-Mar-2026 472 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

What is the usage of onpagehide event in JavaScript?

Akshaya Akki
Akshaya Akki
Updated on 15-Mar-2026 516 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 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 160 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
Showing 51–60 of 328 articles
« Prev 1 4 5 6 7 8 33 Next »
Advertisements