Named Arguments in JavaScript

AmitDiwan
Updated on 17-Jul-2020 08:53:14

233 Views

Following is the code for using named arguments in JavaScript functions −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result {       font-size: 18px;       font-weight: 500;       color: red;    }    .result {       color: rebeccapurple;    } Named arguments in JavaScript functions CLICK HERE Click on the above button to call a function and pass above object to it as argument    let sampleEle ... Read More

Return Statement in JavaScript Switch Statement

AmitDiwan
Updated on 17-Jul-2020 08:47:22

21K+ Views

The JavaScript switch statement can contain return statements if it is present inside a function. The function will return the value in the switch statement and the code after the switch statement will not be executed.Following is the code to have return statements in JavaScript switch statement −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;    } Return statement in JavaScript switch Enter day 1-7 CHECK ... Read More

Group Array of Objects by ID in JavaScript

AmitDiwan
Updated on 17-Jul-2020 08:43:33

2K+ Views

Following is the code to group array of objects by id in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } group the array of objects by Id in JavaScript { name: 'Rohan', age: 18 }, { name: 'Mohan', age: 20 }, { name: 'Shawn', age: 18 }, { name: 'Michael', age: 18 }, { name: 'David', age: 20 } ... Read More

Creating Copy to Clipboard Feature on a Web Page with JavaScript

AmitDiwan
Updated on 17-Jul-2020 08:42:09

190 Views

Following is the code for creating ‘copy to clipboard’ feature on a web page with JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    input,    button {       padding: 8px;    } Creating Copy to Clipboard Copy Text Click on the above button to copy text from the textbox    let resEle = document.querySelector(".result");   ... Read More

Disable Mouse Events on Certain Elements Using JavaScript

AmitDiwan
Updated on 17-Jul-2020 08:38:57

4K+ Views

Following is the code for disabling mouse event on certain elements using JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .size {       font-size: 30px;    } Disable Mouse events using JavaScript This is some text inside a div DISABLE ENABLE Click on the above button to enable or disable mouse events    let resEle ... Read More

Enumerated Types in JavaScript

AmitDiwan
Updated on 17-Jul-2020 08:23:14

156 Views

JavaScript doesn’t support Enums out of the box. The only way to have enums in javaScript is to implement them using objects.Following is the code showing enumerated types in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Enumerated Types in JavaScript CLICK HERE Click on the above button to get the color values    let resEle = document.querySelector(".result");   ... Read More

Embed JavaScript in HTML File

AmitDiwan
Updated on 17-Jul-2020 08:20:18

517 Views

Following is the code to embed JavaScript in html file −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Embed javascript in html file    let resEle = document.querySelector(".result");    resEle.innerHTML += "Inline javaScript loaded" + ""; script.jsresEle.innerHTML += 'External JavaScript loaded ';OutputThe above code will produce the following output −

Explain Shorthand Functions in JavaScript

AmitDiwan
Updated on 17-Jul-2020 08:16:46

1K+ Views

The arrow functions also known as shorthand functions were introduced in ES2015 and allows us to write function in a shorter way. They don’t have their own binding to this and get the this from the surrounding context.Following is the code showing shorthand functions in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Shorthand function in JavaScript CLICK HERE Click ... Read More

Flatten Multi-Dimensional Arrays in JavaScript

AmitDiwan
Updated on 17-Jul-2020 08:15:57

378 Views

Following is the code for flattening multi-dimensional arrays in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,    .sample {       font-size: 20px;       font-weight: 500;    } Flattening multi-dimensional arrays in JavaScript [1,2,3,[4,5],[6,[7,8]]] After flat : CLICK HERE Click on the above button to flat the above array by depth 2    let resEle = document.querySelector(".result");    let sampleEle = document.querySelector(".sample");    let arr = [1, 2, 3, [4, 5], [6, [7, 8]]];    document.querySelector(".Btn").addEventListener("click", () => {       let store = arr.flat(2);       store.forEach((item, index) => {          resEle.innerHTML += index + " : " + item + "";       });    }); OutputOn clicking the ‘CLICK HERE’ button

Flattening Arrays in JavaScript

AmitDiwan
Updated on 17-Jul-2020 08:14:35

335 Views

Following is the code for flattening arrays in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,    .sample {       font-size: 20px;       font-weight: 500;    } Flattening arrays in JavaScript [1,2,3,[4,5],[6,[7,8]]] After flat : CLICK HERE Click on the above button to flat the above array by depth 1    let resEle = document.querySelector(".result");    let sampleEle = document.querySelector(".sample");    let arr = [1,2,3,[4,5],[6,[7,8]]];    document.querySelector(".Btn").addEventListener("click", () => {       let store = arr.flat(1);       store.forEach((item,index) => {          resEle.innerHTML += index + ' : ' + item + '';       });    }); OutputOn clicking the ‘CLICK HERE’ button −

Advertisements