Found 10483 Articles for Web Development

Shared properties in JavaScript

AmitDiwan
Updated on 20-Jul-2020 07:41:09

395 Views

Properties can be shared by attaching them to the prototype property of the object. These properties will be shared among all the instances of the object.Following is the code for sharing properties 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;    } Shared properties in JavaScript CLICK HERE Click on the above button to the view properties of student1 and student2 ... Read More

Passing a function as a callback in JavaScript

AmitDiwan
Updated on 20-Jul-2020 07:38:02

249 Views

Following is the code for passing a function as a callback 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;    } Passing a function as a callback CLICK HERE Click on the above button to pass the add2() function as callback to multiply9() function    let resEle = document.querySelector(".result");    function add2(a) {       return a + 2;    }    function multiply9(fn, num) {       return fn(num) * 9;    }    document.querySelector(".Btn").addEventListener("click", () => {       resEle.innerHTML = "The number returned = " + multiply9(add2, 12);    }); OutputOn clicking the ‘CLICK HERE’ button −

Invoking functions with call() and apply() in JavaScript

AmitDiwan
Updated on 20-Jul-2020 07:36:10

176 Views

Following is the code for invoking functions with call() and apply() 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;    } Invoking functions with call() and apply() Click Here Click on the above buttons to invoke functions with call() and apply() method    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn");    function addNum(num1, num2, num3, num4) { ... Read More

Implementation of Queue in JavaScript

AmitDiwan
Updated on 20-Jul-2020 07:33:10

329 Views

Following is the code to implement queue 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;    }    button {       padding: 6px;       margin: 4px;    } Implementation of queue in JavaScript. Enqueue Dequeue Display Click on the above buttons to perform queue operations    let resEle = document.querySelector(".result");    let BtnEle = ... Read More

Implementation of Stack in JavaScript

AmitDiwan
Updated on 20-Jul-2020 07:29:41

449 Views

Following is the code to implement stack 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;    }    button {       padding: 6px;       margin: 4px;    } Implementation of Stack in JavaScript. Push Pop Display Click on the above buttons to perform stack operations    let resEle = document.querySelector(".result");    let BtnEle = document.querySelector(".Btn"); ... Read More

How do we loop through array of arrays containing objects in JavaScript?

AmitDiwan
Updated on 18-Jul-2020 09:16:06

534 Views

Following is the code to loop through array of arrays containing objects 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;    } Loop through array of arrays containing objects in JavaScript CLICK HERE Click the above button to loop throught the arrObj    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");    let arrObj = [   ... Read More

How to pass event objects from one function to another in JavaScript?

AmitDiwan
Updated on 18-Jul-2020 09:12:43

3K+ Views

Following is the code to pass event objects from one function to another in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    } Pass event objects from one function to another in JavaScript CLICK HERE Click the above button to change its font size and color    function changeFont(event) {       event.target.style.fontSize = "32px";       changeColor(event);    }    function changeColor(event) {       event.target.style.color = "red";    } OutputThe above code will produce the following output −On clicking the ‘CLICK HERE’ button −

How to change an object Key without changing the original array in JavaScript?

AmitDiwan
Updated on 18-Jul-2020 09:09:12

466 Views

Following is the code to change an object key without changing the original array in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    } Change an object Key without changing the original array CLICK HERE Click the above button to change the name object key to fullName    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");    let sampleEle = document.querySelector(".sample");    let obj = [       { name: "Rohan Sharma", age: 12 },     ... Read More

Joining a JavaScript array with a condition?

AmitDiwan
Updated on 18-Jul-2020 09:06:07

624 Views

Following is the code to a JavaScript array with a condition 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;    } Joining a JavaScript array with a condition CLICK HERE Click the above button to join the array elements that are divisible by 2.    let BtnEle = ... Read More

How to join two arrays in JavaScript?

AmitDiwan
Updated on 18-Jul-2020 09:03:20

255 Views

Following is the code to join two arrays together 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;    } Join two arrays in JavaScript CLICK HERE Click the above button to join the above two arrays together.    let BtnEle = document.querySelector(".Btn");    let resEle = document.querySelector(".result");   ... Read More

Advertisements