Found 8591 Articles for Front End Technology

Explain focus events in JavaScript

AmitDiwan
Updated on 16-Aug-2023 14:46:06

1K+ Views

The focus of items on a web page can be determined via focus events, which we will learn about in this article. The numerous browser−provided events that are triggered when an HTML element gains or loses attention are known as focus events in JavaScript. These occasions can be utilised in a number of contexts, for as in response to user actions like clicking on an input field. We can track when a web page element obtains or loses focus with the aid of focus events. There are three main focus events in JavaScript − Focus − This event gets ... Read More

The lastIndex property in JavaScript

AmitDiwan
Updated on 16-Aug-2023 14:28:09

128 Views

In this tutorial, we will learn about the lastIndex property in javascript. In addition to this, we will also learn about how we can use it to manage matches within a string The lastIndex property is a property given by regex objects in JavaScript. It represents the index at which the next search will start within a string passed in the regex, or in simple terms, the index at which to start the next match in a string. When using a regex object with methods like exec(), compile(), etc, the lastIndex property is automatically updated to the index after the ... Read More

What are JavaScript symbols?

AmitDiwan
Updated on 16-Aug-2023 14:24:58

736 Views

A symbol in JavaScript is a primitive data type, introduced in ES6 version update, that represents an immutable and unique identifier. Unlike other primitive types like strings, booleans, numbers, etc, symbols are guaranteed to be unique. This implies that even if two symbols have the same content, they are going to be distinct (separate) entities and not equal to each other. Symbols are primarily used to avoid naming conflicts when adding properties to objects. In this Tutorial, we will learn about symbols in JavaScript. Along with that we will also learn how we can use them to add properties in ... Read More

How to print positive and negative infinity values in JavaScript?

AmitDiwan
Updated on 15-Jul-2020 13:28:01

211 Views

Following is the code for printing positive and negative infinity values in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .num {       font-size: 18px;       font-weight: 500;    } JavaScript Infinity property 1.797693134862315E+10308 -1.797693134862315E+10308 CLICK HERE Click on the above button to add and subtract the above floating numbers by 1 respectively    let sampleEle = document.querySelector(".sample");    let num1 = document.querySelectorAll(".num")[0];    let num2 = document.querySelectorAll(".num")[1];    document.querySelector(".Btn").addEventListener("click", () => {       num1.innerHTML = +num1.innerHTML + 1;       num2.innerHTML = +num2.innerHTML - 1;    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

How to search for a string in JavaScript?

AmitDiwan
Updated on 15-Jul-2020 13:25:44

261 Views

Following is the code for searching a string in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Searching a string in JavaScript The spring season is about to come. CLICK HERE Click on the above button to find the string 'spring' in the above string    let btnEle = document.querySelector(".btn");    let sampleEle = document.querySelector(".sample").innerHTML;    let resEle = document.querySelector(".result");    btnEle.addEventListener("click", () => {       resEle.innerHTML = "The string spring is found at position " + sampleEle.search("spring");    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

NaN and Infinity example in JavaScript

AmitDiwan
Updated on 15-Jul-2020 13:23:32

209 Views

Following is the code to implement NaN and Infinity in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } NaN and Infinity in JavaScript CLICK HERE Click on the above button to see nan and infinity example    let btnEle = document.querySelector(".btn");    let resEle = document.querySelector(".result");    btnEle.addEventListener("click", () => {       resEle.innerHTML = "9/0 = " + 9 / 0 + "";       resEle.innerHTML += 'Number("AJKL") = ' + Number("AJKL") + "";    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Adding options to a