JavaScript exec() Method

AmitDiwan
Updated on 07-May-2020 15:00:01

249 Views

The exec() method executes the search for match and if the matched text is found in the specified string then it is returned otherwise null is returned.Following is the code for the JavaScript exec() Method −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;    } JavaScript exec() Lorem ipsum dolor, sit amet consectetur adipisicing. CLICK HERE Click on the above buttons to execute regex   ... Read More

JavaScript Escape Function

AmitDiwan
Updated on 07-May-2020 14:51:01

766 Views

The escape() function in JavaScript is used for encoding a string. It is deprecated in JavaScript 1.5.Following is the code for the JavaScript escape()Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;    } JavaScript escape() CLICK HERE Click on the above buttons to encode the URI    let sampleEle = document.querySelector(".sample");    let url = "https://www.google.com/images?size=420px&name=8s1f.jpg";    document.querySelector(".Btn").addEventListener("click", () => {       sampleEle.innerHTML = escape(url);    }); OutputOn clicking the “CLICK HERE” button −

JavaScript Error Name Property

AmitDiwan
Updated on 07-May-2020 14:48:00

200 Views

The error name property is used for setting or getting the name of the error.Following is the code for the Error name property −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;    } JavaScript Error name Property CLICK HERE Click on the above buttons to see the error name    let sampleEle = document.querySelector(".sample");    document.querySelector(".Btn").addEventListener("click", () => {       try {          confrm("Are you sure");       } catch (e) {          sampleEle.innerHTML = "Error: " + e.name;       }    }); OutputOn clicking the “CLICK HERE” button −

JavaScript Error Message Property

AmitDiwan
Updated on 07-May-2020 14:43:52

248 Views

The error message property sets or returns an error message in JavaScript. Following is the code for the error message property −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;    } JavaScript Error message Property CLICK HERE Click on the above buttons to see the error message    let sampleEle = document.querySelector(".sample");    document.querySelector(".Btn").addEventListener("click", () => {       try {          confrm('Are you sure');       } catch (e) {          sampleEle.innerHTML = "Error: " + e.message;       }    }); OutputOn clicking the “CLICK HERE” button −

JavaScript encodeURI, decodeURI and Its Components Functions

AmitDiwan
Updated on 07-May-2020 14:37:11

332 Views

The encodeURI() function encodes the complete URI including special characters except except (, / ? : @ & = + $ #) characters.The encodeURIComponent() function encodes some parts of the URI by basically encoding the special characters. It also encodes the following characters − (, / ? : @ & = + $ # )The decodeURI() function decodes the URI generated by the encodeURI() function.The decodeURIComponent() function is used to decode some parts of URI generated by encodeURIComponent().Following is the code for the encodeURI(), decodeURI() and its component functions −Example Live Demo Document    body { ... Read More

Getting Mouse Coordinates in JavaScript

AmitDiwan
Updated on 07-May-2020 14:21:10

502 Views

To get the coordinates of mouse using JavaScript, the code is as follows −Example Live Demo    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 25px;       font-weight: 500;    } Coordinates of mouse Hover the mouse over the screen to get its x and y axis position    let sampleEle = document.querySelector(".sample");    document.body.addEventListener("mousemove", (event) => {       sampleEle.innerHTML = "X axis: " + event.x + " Y axis: " + event.y;    }); OutputThe above code will produce the following output:

Convert String to Boolean in JavaScript

AmitDiwan
Updated on 07-May-2020 14:08:17

294 Views

To convert a string to boolean in JavaScript, the code is as follows −Example Live Demo    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    } Converting string to boolean CLICK HERE Click the above button to convert the string to boolean value    let sampleEle = document.querySelector(".sample");    let inputEle = document.querySelector(".str");    document.querySelector(".Btn").addEventListener("click", () => {       sampleEle.innerHTML += "Using == " + (inputEle.value == "true") + "";       sampleEle.innerHTML += "Using === " + (inputEle.value === "true") + "";    }); OutputOn writing something in the input field other than string ‘true’ and clicking the button −

JavaScript const

AmitDiwan
Updated on 07-May-2020 14:04:50

315 Views

The JavaScript const declarations create variables that cannot be reassigned to some other value or redeclared later. It was introduced in ES2015.Following is the code for JavaScript const declaration −Example Live Demo    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    } Const example CLICK HERE Click the above button to try changing const value    let sampleEle = document.querySelector(".sample");    const a = 33;    sampleEle.innerHTML = "a = " + a + "";    document.querySelector(".Btn").addEventListener("click", () => {       try {          a = 44;       } catch (err) {          sampleEle.innerHTML += "Error : " + err;       }    }); OutputOn clicking the ‘CLICK HERE’ button to change constant value −

JavaScript Chart.js

AmitDiwan
Updated on 07-May-2020 13:50:15

519 Views

Chart.js is an open source JavaScript library. Using Chart.js, add animated, interactive graphs on your website.Following is the code for Chart.js library in JavaScript −Example Live Demo

Auto-Filling One Field Same as Another in JavaScript

AmitDiwan
Updated on 07-May-2020 13:38:41

403 Views

To auto-filling one field same as other, the JavaScript script is as follows −Example Live Demo    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    } JavaScript Auto-filling one field same as other Enter your primary address Address Pin Code Secondary Address same as primary Same Address Enter your secondary address Address Pin Code    let checkEle = document.querySelector(".check");    let addressEle = document.querySelectorAll(".address");    let pinCodeEle = document.querySelectorAll(".pincode");    checkEle.addEventListener("change", (event) => {       if (event.target.checked) {          console.log(addressEle[0].value);          addressEle[1].value = addressEle[0].value;          pinCodeEle[1].value = pinCodeEle[0].value;       }    }); OutputOn filling the primary address and clicking the “Same Address” checkbox −

Advertisements