Found 10483 Articles for Web Development

Implementing Linear Search in JavaScript

AmitDiwan
Updated on 22-Jul-2020 07:48:36

440 Views

Following is the code for implementing linear search in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,.sample {       font-size: 20px;       font-weight: 500;       color: blueviolet;    }    .sample{       color:red;    } Implementing linear search [1,19,5,11,22,55] CLICK HERE Click on the above button to search for 22 in the above array    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    let arr = [1,19,5,11,22,55];    BtnEle.addEventListener("click", () => {       for(let i=0;i

ES6 Property Shorthands in JavaScript

AmitDiwan
Updated on 22-Jul-2020 07:47:39

183 Views

In ES6, if the object key name and variables passed as properties value have same name then we can simply omit the value name and only specify the key name.Following is the code for property shorthands in JavaScript −Example Live Demo Document body {     font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;       color: blueviolet;    } ES6 Property Shorthands in JavaScript CLICK HERE Click on the above ... Read More

Awaiting on dynamic imports in JavaScript.

AmitDiwan
Updated on 22-Jul-2020 07:42:30

173 Views

Note − You will need a localhost server to run this example −Following is the code for dynamic imports 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;    } Awaiting on dynamic imports in JavaScript CLICK HERE Click on the above button to dynamically import modules    document.querySelector(".Btn").addEventListener("click", loadModule);    let resEle = document.querySelector(".result");    async function loadModule() {   ... Read More

Nesting template strings in JavaScript

AmitDiwan
Updated on 22-Jul-2020 07:40:39

588 Views

Following is the code for nesting 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;       color: blueviolet;    } Nesting template strings in JavaScript CLICK HERE Click on the above button to display the fullName using nested template string    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    function fullName(fName, lName) {       return fName + " " + lName;    }    let firstName = "Rohan";    let lastName = "Sharma";    BtnEle.addEventListener("click", () => {       resEle.innerHTML = `FirstName = ${firstName} and lastname = ${lastName} and       fullname = ${fullName(          `${firstName}`,          `${lastName}`       )}`;    }); OutputOn clicking the ‘CLICK HERE’ button −

Function borrowing in JavaScript.

AmitDiwan
Updated on 21-Jul-2020 07:45:55

379 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

How to transform JavaScript arrays using maps?

AmitDiwan
Updated on 21-Jul-2020 07:43:53

113 Views

Following is the code to transform JavaScript arrays using maps.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;    } Transform JavaScript arrays using maps [22,33,44,55] CLICK HERE Click on the above button to square each element of the above array    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    let arr = [22, 33, 44, 55];    BtnEle.addEventListener("click", () => {       resEle.innerHTML = arr.map((a) => a * a);    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Explain higher order functions in JavaScript

Vasireddy Bindu Hasitha
Updated on 23-Apr-2024 12:13:51

492 Views

What is a Higher Order Function in JavaScript? JavaScript being a multi paradigm language, it supports procedural programming, functional programming and object oriented programming. Since it is also a functional programming language javascript handles functions as a first class entities, where functions can be assigned to a variable, set it as an object's property, and can pass them as an argument to another function. This characteristic in javascript helps in implementing Higher Order Functions, which can operate on other functions either by taking them as an argument or by returning them. Let us take an example and implement it ... Read More

Is it possible to de-structure to already-declared variables? In JavaScript?

AmitDiwan
Updated on 21-Jul-2020 07:39:51

147 Views

Following is the code to de-structure already declared variables 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;    } De-structure to already-declared variables CLICK HERE Click on the above button to destructure the personObj object    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    let name, age, personObj;    personObj = {       name: "Rohan",       age: 19,    };    BtnEle.addEventListener("click", () => {       ({ name, age } = personObj);       resEle.innerHTML = " name = " + name + "age = " + age;    }); OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

Is there an elegant way of passing an object of parameters into a function?

AmitDiwan
Updated on 21-Jul-2020 07:38:18

86 Views

Following is the code to pass an object of parameters to a function −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .sample {       color: red;    } Passing an object of parameters into a function CLICK HERE Click on the above button to add 4 object values by passing them to a function    let ... Read More

How to merge objects into a single object array with JavaScript?

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

268 Views

Following is the code to merge objects into a single object 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;    }    .sample {       color: red;    } Merge objects into a single object array [{id:22, class:7}, {name:'Rohan', age:12}, {state:'Delhi', country:'India'}] CLICK HERE Click on the above button to merge the above objects inside array into ... Read More

Advertisements