Author: ShairyPortfolio
-

Template Literals/ Rest Parameter & Spread Operator in ES6
Template Literals in ES6 The template literal has made it easier to include variables inside a string. const first_name = “shairy”; const last_name = “kalra”; Before ES6 console.log(‘Hello ‘ + first_name + ‘ ‘ + last_name); Now console.log(`Hello ${first_name} ${last_name}`); Rest Parameter in ES6 Rest parameter are used to represent an indefinite number of arguments…
-

Destructuring in ES6
The destructuring syntax makes it easier to assign values to a new variable. Array Destructuring – show you how to assign elements of an array to variables. function getScores() { return [70, 80, 90]; } Before ES6 var x = scores[0], y = scores[1], z = scores[2]; console.log(scores[0]); console.log(scores[1]); console.log(scores[2]); Now var…
-

Function in JS / ES6
Default Function <script> function Demo() { alert(“I am a Default Function”); } Demo(); </script> Parametrized Function <script> function Demo(type) { document.write(“I am a “+ type + ” Function”); } Demo(“parameterized”); </script> Default Parameter Value <script> function Demo(type=”default parameter”) …
-

JSON format of object
<script> let student = { name: “shairy”, age: 30, isAdmin: false, courses: [“html”, “css”, “js”], wife: null, }; let json = JSON.stringify(student); alert(typeof json); // we’ve got a string! alert(json); let jobj = JSON.parse(json); alert(jobj.name); </script>