Tag: es6
-

String Methods in ES6
String.includes() The includes() method returns true if a string contains a specified value, otherwise false: String.startsWith() The startsWith() method returns true if a string begins with a specified value, otherwise false: String.endsWith() The endsWith() method returns true if a string ends with a specified value, otherwise false: let text = “Hello guys, welcome to my…
-

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”) …
-

Getter Setter method in ES6
<script> let user = { name: “Etude”, surname: “pro”, get fullName() { return this.name + ” ” + this.surname; }, set fullName(value) { [this.name, this.surname] = value.split(” “); }, set fullName1(obj) { this.name = obj.firstName; this.surname = obj.lastName; }, }; …