Javascript Articles

Page 61 of 534

How to print positive and negative infinity values in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 259 Views

Following is the code for printing positive and negative infinity values in JavaScript −Example 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 −

Read More

What are associative Arrays in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 4K+ Views

Associative arrays are basically objects in JavaScript where indexes are replaced by user defined keys. They do not have a length property like normal array and cannot be traversed using normal for loop.Following is the code for associative arrays in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Associative array in JavaScript CLICK HERE Click on the above button to create a associative array and ...

Read More

Explain common code blocks in JavaScript switch statement?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 302 Views

Following is the code to implement common code blocks in JavaScript switch statement −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } JavaScript Switch statement Enter day 1-7 CHECK Click on the above button to check which day it is    let dayVal = document.querySelector(".day");    let resEle = document.querySelector(".result");    document.querySelector(".Btn").addEventListener("click", () => {       switch (parseInt(dayVal.value)) {       ...

Read More

Explain Strict Comparison in JavaScript switch statement?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 454 Views

The JavaScript switch statement only uses strict comparison (===) and doesn’t converts type if matches are not found using strict comparison and will immediately execute the default statement.Following is the code for strict comparison in JavaScript switch statement −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } JavaScript Switch statement strict comparison Enter day 1-7 CHECK Click on the above button to check if switch performs ...

Read More

How to test and execute a regular expression in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 304 Views

Following is the code for testing and executing a regular expression in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Testing and executing regular expressions CLICK HERE Click on the above button to test and execute the regular expression    let sampleEle=document.querySelector('.sample');    let resEle = document.querySelector('.result');    let str = 'Hello world. This is a beautiful world';    sampleEle.innerHTML =str; ...

Read More

Explain JavaScript Regular Expression modifiers with examples

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 681 Views

The JavaScript regular expression modifiers are optional part of a regular expression and allow us to perform case insensitive and global searchers. The modifiers can also be combined together.Following are the modifiers −ModifierDescriptiongIt enables global matching and returns all the matched results instead of stopping at first matchiIt enables case insensitive matchingmIt enables multiline matchingExampleFollowing is the code for strict comparison in JavaScript switch statement − Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500; ...

Read More

How to preview an image before it is uploaded in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 299 Views

To upload an image, use FileReader() in JavaScript. Following is the JavaScript code −Example Document    function readImage(fileInput) {       if (fileInput.files && fileInput.files[0]) {          var takingInputFile = new FileReader();          takingInputFile.onload = function(event) {             $('#chooseImage').attr('src', event.target.result);          }          takingInputFile.readAsDataURL(fileInput.files[0]);       }    }    $("#yourImage").change(function() {       readImage(this);    }); To run the above program, save the file name anyName.html(index.html) and right click on the file and select the option Open with live server in VS code editor.Output

Read More

Hide div that contains specific text with JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 2K+ Views

At first, you need to extract the extract the div class with the help of getElementsByClassName() and iterate over the for loop and use the OR condition to show the specific text.Also, set yourDiv.style.display=’none’.Following is the JavaScript code −Example Document header content footer    let attribute = document.getElementsByClassName('block');    for (let i = 0; i < attribute.length; i++) {       let impDiv = attribute[i];       let value = impDiv.innerHTML.trim();       if (value == 'header' || value == 'footer') ...

Read More

How to create a constant array in JavaScript? Can we change its values? Explain.

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 2K+ Views

To create a const array in JavaScript we need to write const before the array name. The individual array elements can be reassigned but not the whole array.Following is the code to create a constant array in JavaScript.Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Const array in JavaScript CLICK HERE Click on the above button to change array values and reassign the array ...

Read More

Get number from user input and display in console with JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 3K+ Views

You can use # to get the value when user clicks the button using document.querySelector(“”); Following is the JavaScript code −Example Document Example: choose a number between 1 to 100 Give a number: Click Me    function example() {       let btn = document.querySelector("#choose");       let randomNumber = Math.ceil(Math.random() * 100);       btn.onclick = function() {          let givenNumber = document.querySelector("#inputNumber").value;          let valueInt = parseInt(givenNumber, 100);     ...

Read More
Showing 601–610 of 5,338 articles
« Prev 1 59 60 61 62 63 534 Next »
Advertisements