Static Properties in JavaScript

AmitDiwan
Updated on 20-Jul-2020 07:47:03

157 Views

Static properties are assigned to the class function itself and not to its prototype property. These properties can be called directly without instantiating any objects.Following is the code for static 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;    } Static Properties in JavaScript CLICK HERE Click on the above button to the access the static property school of Student ... Read More

Share Methods in JavaScript

AmitDiwan
Updated on 20-Jul-2020 07:45:25

647 Views

Methods can be shared by attaching them to the prototype property of the object. These methods will be shared among all the instances of the object.Following is the code for sharing methods 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 methods in JavaScript CLICK HERE Click on the above button to the call the displayInfo method of student1 ... Read More

Shared Properties in JavaScript

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

402 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

257 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

186 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

334 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

458 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

Reordered Power of 2 in C++

Arnab Chakraborty
Updated on 19-Jul-2020 19:00:29

266 Views

Suppose we have a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is non-zero. We have to check whether we can do this in a way such that the resulting number is a power of 2. So if the number is like 46, then the answer will be true.To solve this, we will follow these steps −Define a method called count, this will take x as inputret := 0while x is not 0ret := ret + 10 ^ last digit of xx := x / 10return retFrom the main ... Read More

Loop Through Array of Arrays Containing Objects in JavaScript

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

544 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

Pass Event Objects Between Functions 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 −

Advertisements