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 488 of 534
How to Create GUID / UUID in JavaScript?
A Globally Unique Identifier (GUID) or Universally Unique Identifier (UUID) is a 128-bit value used as a unique identifier in software development. It's typically represented as a 32-character hexadecimal string with hyphens, like: de305d84-75c4-431d-acc2-eb6b0e5f6014. Here are several JavaScript methods to generate GUIDs/UUIDs. Using Random Number Generation The most common approach uses Math.random() to generate a UUID v4 format: function generate_uuidv4() { return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { var uuid = Math.random() * 16 | 0, v = c == 'x' ? uuid : (uuid & 0x3 ...
Read MoreHow to use finally on promise with then and catch in Javascript?
JavaScript asynchronous programming uses promise objects that don't block execution but signal when operations complete. Promises can either resolve successfully or reject with an error. The finally() method executes cleanup code regardless of the promise outcome, similar to finally blocks in synchronous try-catch statements. Syntax promise .then(result => { // handle success }) .catch(error => { // handle error }) .finally(() => { // ...
Read MoreHow to enable a strict mode in javascript?
In JavaScript, there are two different programming paradigms. The sloppy mode, sometimes referred to as the simple mode, is activated by default. We don't have to write the code strictly according to guidelines in this manner. On the other side, there is also the strict mode. This setting allows the environment to have some rigid constraints. Strict mode has different semantics than regular code and is not a subset of sloppy mode. This article will explain how to enable strict mode in JavaScript and will also go over some of the features of "Strict" Mode. Syntax Different scopes ...
Read MoreHow to call JavaScript function in an alert box?
To call a JavaScript function in an alert box, you can use the alert() function, a built-in function in JavaScript that displays an alert dialog with a specified message. An alert box is a simple dialog box that displays a message to the user and provides an OK button. It is a built-in function in JavaScript that is often used for debugging or displaying simple notifications to the user. Here's an example of how to use the alert() function in JavaScript: alert("Hello, World!"); ...
Read MoreCalculating median of an array in JavaScript
In this problem statement, our task is to calculate the median of an array with the help of Javascript functionalities. There are several ways that can be used to solve this task. One simple method to calculate median is using the built-in function of Javascript. Understanding the Problem The problem statement is to write a function in Javascript that will help to calculate the median of a given array. The median is the middle value when numbers are arranged in ascending order. For example: Array [1, 2, 3, 4, 5] has median 3 (middle element) Array ...
Read MoreFind number of spaces in a string using JavaScript
In JavaScript, counting spaces in a string is a common task that can be accomplished using several built-in methods. This article explores different approaches to find the number of space characters in a string. Problem Overview Given a string with space characters, we need to count how many spaces it contains. For example, the string "Hello world example" contains 2 spaces. const exampleString = "This is an example of counting spaces"; // Expected output: 6 spaces Method 1: Using split() Method The split() method divides a string into an array based on a ...
Read MoreHow to find distance between items on array JavaScript?
In JavaScript, finding the distance between array items means calculating how many positions separate two elements. The distance is measured as the absolute difference between their index positions. Understanding the Problem Array distance represents the number of steps needed to move from one element to another. For example, in the array [1, 2, 3, 4, 5], the distance between elements 2 and 4 is 2 because their indices are 1 and 3 respectively, giving us |3 - 1| = 2. Basic Distance Calculation The simplest approach uses indexOf() to find element positions and calculates the absolute ...
Read MoreDifference between == and === operator in JavaScript
JavaScript is widely used to create interactive web pages. It has many frameworks such as React JS, Angular JS, Node JS, etc. Like any other programming language, JavaScript also provides operators like arithmetic, relational, comparison operators, etc. The equality operator, i.e., "==" is one such comparison operator that checks whether the LHS is equal to RHS or not. This operator is present in all other programming languages but it is somewhat different in JavaScript. This is due to the fact that JavaScript is a loosely typed language, whereas all other languages are strictly typed. As JS is loosely typed, it ...
Read MoreExplain focus events in JavaScript
Focus events in JavaScript are triggered when HTML elements gain or lose focus on a web page. These events are essential for creating interactive user interfaces and handling form interactions effectively. Focus events occur when users interact with focusable elements like input fields, buttons, or links through clicking, tabbing, or keyboard navigation. Understanding these events helps create responsive and accessible web applications. Types of Focus Events JavaScript provides four main focus events: focus − Triggered when an element gains focus. Does not bubble up the DOM tree. blur − ...
Read MorePreventDefault( ) vs Return false in JavaScript?
In JavaScript, when handling events, you often need to prevent the default browser behavior. The two common approaches are preventDefault() and return false, but they work differently. The preventDefault() method stops only the default action, while return false stops both the default action and event propagation. Key Differences preventDefault() return false Method available on event objects JavaScript statement that can be used anywhere Stops only the default behavior Stops default behavior AND event propagation Allows event to continue bubbling up Stops event bubbling and function execution ...
Read More