Found 6710 Articles for Javascript

Can we assign new property to an object using deconstruction in JavaScript?

AmitDiwan
Updated on 18-Jul-2020 08:18:28

123 Views

Following is the code to assign new property to an object using deconstruction 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;    } Assign new property to an object using deconstruction {"a":11, "b":22, "c":44} CLICK HERE Click on the above button to assign values to obj by destructuring above object ... Read More

JavaScript -Short-circuiting in boolean

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

197 Views

Following is the code for short circuiting in boolean −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       font-weight: 500;       color: blueviolet;    } Short-circuit Boolean && short circuit evaluation || short circuit evaluation Click on the above button to see the the short circuit evaluation    let resEle = document.querySelector(".result");    let BtnEle = document.querySelectorAll(".Btn");    function retTrue() {       resEle.innerHTML += "True ... Read More

Short Circuit Assignment in JavaScript

AmitDiwan
Updated on 18-Jul-2020 08:10:28

214 Views

Following is the code to implement short circuit assignment 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;    } Short-circuit assignment a=22 || 0 || 0b=0 && 22 && 22 Click Here Click on the above button to see the values of variable a and b in the ... Read More

Formatting JavaScript Object to new Array

AmitDiwan
Updated on 18-Jul-2020 08:13:51

522 Views

Following is the code to format JavaScript object to new Array −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Formatting JavaScript Object to new Array. CLICK HERE Click on the above button to format the school object to an array    const school = {       name: "St Marks",       address: "Delhi",       students: ... Read More

Short-circuit evaluation in JavaScript

AmitDiwan
Updated on 18-Jul-2020 08:08:40

1K+ Views

Short circuit evaluation basically works with the && and || logical operators. The expressions are evaluated left to right.For && operator − Short circuit evaluation with &&(AND) logical operator means if the first expression evaluates to false then whole expression will be false and the rest of the expressions will not be evaluated.For || operator − Short circuit evaluation with ||(OR) logical operator means if the first expression evaluates to true then the whole expression will be true and the rest of the expressions will not be evaluated.Following is the code for short circuit evaluation in JavaScript −Example Live Demo ... Read More

JavaScript code to print last element of an array

AmitDiwan
Updated on 18-Jul-2020 08:11:05

221 Views

Following is the code to print last element of an 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;    }    .result {       color: red;    } JavaScript code to print last element of an array. CLICK HERE Click on the above button to get the last element of the above array    let resEle = ... Read More

Rounding and truncating numbers in JavaScript.

AmitDiwan
Updated on 18-Jul-2020 08:06:32

4K+ Views

There are two functions in JavaScript for rounding and truncating numbers: Math.round() and Math.trunc() respectively −Math.round() − = It rounds the decimal number to the nearest integer value.Math.trunc() − = It simply removes the fractional part of the decimal number and converts it to a whole number.Following is the code for rounding and truncating numbers 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; ... Read More

How to parse array of objects inside another object using maps or forEach?

AmitDiwan
Updated on 18-Jul-2020 08:05:09

143 Views

Following is the code to parse array of objects inside another object using maps or forEach −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    } Parse array of objects inside object CLICK HERE Click on the above button to parse the json object    let json = {       storeData: [          {       ... Read More

Does JavaScript support block scope?

AmitDiwan
Updated on 18-Jul-2020 08:03:27

227 Views

JavaScript supports block scope only for variables that were declared using let or const keyword. Variables declared using var support function scope but not block scope.Following is the code for displaying block scope 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;    } Block scope JavaScript Click Here Click on the above button to create variables with var and let ... Read More

The new operator in JavaScript

AmitDiwan
Updated on 18-Jul-2020 08:01:26

409 Views

The new operator is used for creating a user-defined object type instance of one of the builtin object types that has a constructor function.Following is the code for new operator 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;    } New Operator in JavaScript Click Here Click on the above button to create the object person1 from Person constructor ... Read More

Advertisements