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
Programming Scripts Articles
Page 6 of 33
What will happen if a semicolon is misplaced in JavaScript?
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 MoreHow to check whether a value is a safe integer or not in JavaScript?
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 MoreHow to convert Unicode values to characters in JavaScript?
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 MoreFor Hosts Locale how to convert a string to lowercase letters in JavaScript?
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 MoreHow to return a random number between 0 and 199 with JavaScript?
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 MoreWhat is the role of pageXOffset property in JavaScript?
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 MoreWhat is the usage of onpageshow event in JavaScript?
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 MoreWith JavaScript RegExp search a hexadecimal number character.
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 MoreWhat is the usage of onpagehide event in JavaScript?
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 MoreHow to return the "time" portion of the Date as a string using the current locale's conventions?
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