Following is the code to destructure function parameters in JavaScript −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; } De structuring function parameters CLICK HERE Click on the above button to call a function and pass above object to it as argument let sampleEle = document.querySelector(".sample"); ... Read More
Following is the code to check if a document is ready in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: blueviolet; } Check if a document is ready Check Click on the above button to see document state let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); resEle.innerHTML = document.readyState + ""; BtnEle.addEventListener("click", () => { if (document.readyState === "complete") { resEle.innerHTML = "The page has finished loading completely"; } else { resEle.innerHTML = "The page is still loading"; } }); OutputOn clicking the ‘Check’ button −
The generator.throw() method is used to pass an error to the yield. The generator resumes the execution after throw has been called by throwing an error and returning object with properties done and value.Following is the code for generator.throw() in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .result { color: red; } generator.throw() method ... Read More
Following is the code to reduce arrays in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: red; } .result { color: blueviolet; } button { padding: 8px; } Reduce arrays javascript [1,3,5,6,9,22,15] Sum Click on the above button to sum the elements of the array let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); let sampleEle = document.querySelector(".sample"); let arr = [1, 3, 5, 6, 9, 22, 15]; sampleEle.innerHTML = arr; BtnEle.addEventListener("click", () => { resEle.innerHTML = "Sum = " + arr.reduce((sum, prev) => { return sum + prev; }); }); OutputOn clicking the ‘Sum’ button −
Following is the code for breaking a loop in functional programming −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } Breaking a loop in functional programming JavaScript Click here Click on the above button to iterate fruitArr array and exit if peach is found let resEle = document.querySelector(".result"); let fruitArr = ["apple", "mango", "peach", "papaya", "watermelon"]; document.querySelector(".Btn").addEventListener("click", () => { fruitArr.some(function (fruit) { if (fruit === "peach") { return true; } resEle.innerHTML += fruit + ""; }); }); OutputOn clicking the ‘Click here’ button −
Following is the code for continuing a loop in functional programming JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } Continuing a loop in functional programming JavaScript Click here Click on the above button to iterate fruitArr and skip mango and peach or not let resEle = document.querySelector(".result"); let fruitArr = ["apple", "mango", "peach", "papaya", "watermelon"]; document.querySelector(".Btn").addEventListener("click", () => { fruitArr.some(function (fruit) { if (fruit === "mango" || fruit === "peach") { return false; } resEle.innerHTML += fruit + ""; }); }); OutputOn clicking the ‘Click here’ button −
Import as allows us to import a named module under different name.Export as allows us to export a named module under different name.Following is the code for import as and export as construct 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; } Import as and Export as in JavaScript CLICK HERE Click on the above button to execute the imported ... Read More
Following is the code for getting all unique values in a JavaScript array −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result, .sample { font-size: 18px; font-weight: 500; color: rebeccapurple; } .result { color: red; } Get all unique values in a array Click here Click on the above button to remove the duplicate values from the above array let resultEle = document.querySelector(".result"); let sampleEle = document.querySelector(".sample"); let arr = [2, 3, 4, 2, 3, 4, "A", "A", "B", "B"]; sampleEle.innerHTML = "arr = " + arr; document.querySelector(".Btn").addEventListener("click", () => { let set1 = new Set(arr); resultEle.innerHTML = "arr = " + [...set1] + ""; }); OutputOn clicking the ‘Click here’ button −
Following is the code passing empty parameter to a method in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: blueviolet; } Passing empty parameter to a method Click here Click on the above button to call multiply function and pass empty parameters to it let resEle = document.querySelector(".result"); let BtnEle = document.querySelector(".Btn"); function multiply(a = 2, b = 4) { return a * b; } BtnEle.addEventListener("click", () => { resEle.innerHTML = "The multiplication of numbers = " + multiply(); }); OutputOn clicking the ‘Click here’ button −
Partial functions allow takes a function as an argument and along with it takes arguments of other types too. It then uses some of the arguments passed and returns a function that will take the remaining arguments. The function returned when invoked will call the parent function with the original and its own set of arguments.Following is the code for partial functions in JavaScript −Example Live Demo Document body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; ... Read More
 
 Data Structure
 Data Structure Networking
 Networking RDBMS
 RDBMS Operating System
 Operating System Java
 Java MS Excel
 MS Excel iOS
 iOS HTML
 HTML CSS
 CSS Android
 Android Python
 Python C Programming
 C Programming C++
 C++ C#
 C# MongoDB
 MongoDB MySQL
 MySQL Javascript
 Javascript PHP
 PHP