Javascript Articles - Page 368 of 534

JavaScript Error name Property

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

211 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

258 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

352 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

JavaScript - Creating a Custom Image Slider

Disha Verma
Updated on 24-Apr-2025 16:44:12

1K+ Views

An image slider is a user interface component in JavaScript that allows users to view a series of images in a slideshow format. It is also known as a carousel or slideshow. An image slider consists of navigation buttons (such as next and previous buttons) that allow users to navigate from one image to the other. With the help of basic HTML for structuring and CSS for designing or making the image slider presentable, along with simple JavaScript logic, you can create an image slider efficiently. This article will guide you through creating a basic image slider with navigation buttons. ... Read More

JavaScript – Getting Coordinates of mouse

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

516 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:

JavaScript Convert an array to JSON

Vivek Verma
Updated on 02-Nov-2022 10:47:32

2K+ Views

An array is a special object in JavaScript, that stores multiple types of values which means that it can store an integer value, string value, or float value simultaneously. There are various ways to create an array in JavaScript, following is the syntax to do so − var array = [value1, value2, value3, …]; or var array = new Array(size); or var array = new Array(element1, element2, …); Where the value is the elements of the array so it can be of any type. The JSON is an object notation in JavaScript that is used to represent structured data ... Read More

JavaScript Const

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

328 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 clearTimeout() & clearInterval() Method

Shriansh Kumar
Updated on 30-Jul-2024 16:32:42

2K+ Views

In JavaScript, the clearTimeout() and clearInterval() methods are used to clear timers. When we set a timer using setTimeout() or setInterval() methods, the browser allocates memory to track it. Therefore, we use these methods to release that memory and avoid unnecessary function calls. It is best practice to clear timers when they are no longer needed. In this article, we will learn how the clearTimeout() and clearInterval() methods help to clear timers. JavaScript clearTimeout() method The clearTimeout() method in JavaScript clears the timeout that has been previously set by the setTimeout() function. It accepts a single integer value as a ... Read More

JavaScript Auto-filling one field same as other

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

411 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 −

JavaScript symbol.@@toPrimitive() function

AmitDiwan
Updated on 07-May-2020 13:27:48

154 Views

The symbol.@@toPrimitive() function converts a symbol object to a primitive value.SyntaxSymbol()[Symbol.toPrimitive](hint)The hint value specifies the type eg − number, string, etc and is an optional argument.Following is the code for symbol.@@toPrimitive() function −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    div {       font-size: 20px;       font-weight: 500;    } JavaScript symbol.@@toPrimitive() function CLICK HERE Click on the above button to add the object with a number.    let fillEle = document.querySelector(".sample");   ... Read More

Advertisements