Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Javascript Articles
Page 56 of 534
Undeclared vs Undefined? In JavaScript
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 MoreinnerHTML vs innerText in JavaScript.
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 MoreHow do JavaScript primitive/object types passed in functions?
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 MoreEscape characters in JavaScript
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 MoreHow to borrow methods in JavaScript?
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 MorePassing empty parameter to a method in JavaScript
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 MoreWhat are Partial functions in JavaScript?
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 MoreHow to get all unique values in a JavaScript array?
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 MoreExplain import “as” and Export “as” constructs in JavaScript.
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 MoreBreaking a loop in functional programming JavaScript.
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