Found 6710 Articles for Javascript

Breaking a loop in functional programming JavaScript.

AmitDiwan
Updated on 17-Jul-2020 07:35:27

160 Views

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 −

Explain import “as” and Export “as” constructs in JavaScript.

AmitDiwan
Updated on 17-Jul-2020 07:32:33

208 Views

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

How to get all unique values in a JavaScript array?

AmitDiwan
Updated on 17-Jul-2020 07:31:41

435 Views

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 −

What are Partial functions in JavaScript?

AmitDiwan
Updated on 17-Jul-2020 07:27:35

3K+ Views

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

Passing empty parameter to a method in JavaScript

AmitDiwan
Updated on 17-Jul-2020 07:28:12

1K+ Views

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 −

How to borrow methods in JavaScript?

AmitDiwan
Updated on 17-Jul-2020 07:24:59

151 Views

The call(), apply() and bind() are used to borrow methods in JavaScript.Following is the code for borrowing methods 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;    } Borrowing a method in JavaScript CLICK HERE Click on the above button to borrow the welcome method of object obj ... Read More

object.is() in equality comparison JavaScript

AmitDiwan
Updated on 17-Jul-2020 07:25:56

115 Views

The object.is() method introduced in ES6 as a way to compare two values. These two values can either be primitives or objects. It does a little better comparison than == and ===.Following is the code for object.is() in equality comparison −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: blueviolet;    } Object.is() equality comparsion Click here Click on the above button to compare objects ... Read More

Event bubbling vs event capturing in JavaScript?

AmitDiwan
Updated on 17-Jul-2020 07:23:13

977 Views

Event Bubbling − Whenever an event happens on an element, the event handlers will first run on it and then on its parent and finally all the way up to its other ancestors.Event Capturing − It is the reverse of the event bubbling and here the event starts from the parent element and then to its child element.Following is the code for event bubbling vs event capturing in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px; ... Read More

Undefined in JavaScript

AmitDiwan
Updated on 17-Jul-2020 07:19:59

296 Views

The JavaScript undefined property specifies if a variable has been declared or assigned a value yet.Following is the code implementing the JavaScript undefined property −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample {       font-size: 18px;       font-weight: 500;       color: red;    } JavaScript undefined property CLICK HERE CLICK the above button to know if variable age has been defined or not    let sampleEle = document.querySelector(".sample");    let age;   ... Read More

Template strings in JavaScript.

AmitDiwan
Updated on 17-Jul-2020 07:16:35

533 Views

Template were introduced in ES6 to allow embed expressions inside a string. Instead of ‘’ or “” quotation marks they use the backticks (``). They offer a much better way of string interpolation and expressions can be embedded in a way like ${a+b}. It offers a much nicer syntax than the + operator.Following is the code for template strings in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;       ... Read More

Advertisements