Javascript Articles

Page 56 of 534

Undeclared vs Undefined? In JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

Undeclared − It occurs when a variable which hasn’t been declared using var, let or const is being tried to access.Undefined − It occurs when a variable has been declared using var, let or const but isn’t given a value.Following is the code for undeclared and undefined in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: blueviolet;    } Undeclared vs Undefined Click ...

Read More

innerHTML vs innerText in JavaScript.

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

innerHTML − The innerHTML property returns the text, including all spacing and inner element tags. It preserves the formatting of the text and all the extra tags like , etc.innerText − The innerText property returns just the text, removing the spacing and the inner element tags.Following is the code for innerHTML and innerText in JavaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,    .sample {       font-size: 18px;       font-weight: 500;       color: red;    } ...

Read More

How do JavaScript primitive/object types passed in functions?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 266 Views

Following is the code to pass JavaScript primitive and object types to function −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: blueviolet;    } Passing primitive/object types to function Click here Click on the above button to pass primitive and object to a function and call it    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");    let person = { name: ...

Read More

Escape characters in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 9K+ Views

Escape characters are characters that can be interpreted in some alternate way then what we intended to. To print these characters as it is, include backslash ‘\’ in front of them. Following are the escape characters in JavaScript −CodeResult\bBackspace\fForm FeedNew Line\rCarriage Return\tHorizontal Tabulator\vVertical Tabulator'Single quote"Double quote\BackslashFollowing is the code implement escape character Backslash in javaScript −Example Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;    } Escape characters in JavaScript    let str = 'Hello World "This" is some sample \ Text ' ';    let resEle = document.querySelector(".result");    resEle.innerHTML = str; Output

Read More

How to borrow methods in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 198 Views

The call(), apply() and bind() are used to borrow methods in JavaScript.Following is the code for borrowing methods in JavaScript −Example 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

Passing empty parameter to a method in JavaScript

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 1K+ Views

Following is the code passing empty parameter to a method in JavaScript −Example 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 −

Read More

What are Partial functions in JavaScript?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 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 Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;   ...

Read More

How to get all unique values in a JavaScript array?

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 495 Views

Following is the code for getting all unique values in a JavaScript array −Example 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 −

Read More

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

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 244 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 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 function ...

Read More

Breaking a loop in functional programming JavaScript.

AmitDiwan
AmitDiwan
Updated on 11-Mar-2026 191 Views

Following is the code for breaking a loop in functional programming −Example 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 −

Read More
Showing 551–560 of 5,338 articles
« Prev 1 54 55 56 57 58 534 Next »
Advertisements