Found 6710 Articles for Javascript

Creating a JavaScript array with new keyword.

AmitDiwan
Updated on 15-Jul-2020 13:43:05

197 Views

Following is the code for creating a JavaScript array with new keyword −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Creating array with new keyword CLICK HERE Click on the above button to create a new array and display it    let resEle = document.querySelector(".result");    document.querySelector(".Btn").addEventListener("click", () => {    let arr = new Array(1, 2, 3, 4, "A", "B", "C", "D");       resEle.innerHTML = "arr = " + arr;    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button−

What is meant by Splicing an array in JavaScript? Explain with an example

AmitDiwan
Updated on 15-Jul-2020 13:34:04

523 Views

Splicing an array means to use the Array.splice() method for adding or removing items from the array. The items removed are returned as an array.Following is the code for splicing an array in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result {       font-size: 20px;       font-weight: 500;    } Splicing an array in JavaScript CLICK HERE Click on the above button to add items after second element   ... 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 −

How to delete object properties in JavaScript?

AmitDiwan
Updated on 15-Jul-2020 13:21:27

185 Views

Following is the code for deleting object properties in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Delete object properties in JavaScript Before Deleting After deleting CLICK HERE Click on the above button to delete object properties    let btnEle = document.querySelector(".btn");    let resEle = document.querySelector(".result");    let sampleEle = document.querySelector(".sample");    let obj = {       firstName: ... Read More

How to create an object and access its properties in JavaScript?

AmitDiwan
Updated on 15-Jul-2020 13:18:51

234 Views

Following is the code creating an object and accessing its properties in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Hoisting in JavaScript CLICK HERE Click on the above button to create and access a object    let btnEle = document.querySelector(".btn");    let resEle = document.querySelector(".result");    let obj = {       firstName: "Rohan",       lastName: "Sharma",   ... Read More

Explain hoisting in JavaScript

AmitDiwan
Updated on 15-Jul-2020 13:16:02

383 Views

Hoisting allows us to call functions and variables (declared with var) before they are being defined by moving them to the top of their scope before the execution of code begins.Following is the code showing hoisting for variables and functions in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Hoisting in JavaScript Calling functions and variables before they are defined CLICK HERE ... Read More

How to import and export a module/library in JavaScript?

AmitDiwan
Updated on 15-Jul-2020 13:12:59

2K+ Views

Note − To run this example you will need to run a localhost server.Following is the code for importing and exporting a module/library in JavaScript −ExampleINDEX.html Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;    } JavaScript Importing and Exporting Modules IMPORT Click on the above button to import module script.jsimport test from './sample.js'; document.querySelector('.Btn').addEventListener('click', ()=>{    test(); })sample.jslet resultEle = document.querySelector(".result"); export default ... Read More

Explain ‘dotAll’ flag for regular expressions in JavaScript

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

247 Views

The dotAll flag returns true or false depending upon if the s flag has been set in the regular expression or not.Following is the code to implement dotAll flag for regular expressions in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } dotAll flag for regular expressions CLICK HERE Click on the above button to know if s flag has been set in regex or ... Read More

Advertisements