Home  >  Article  >  Web Front-end  >  How does ES6 (ES2015) evolve and bring new features to modern JavaScript?

How does ES6 (ES2015) evolve and bring new features to modern JavaScript?

WBOY
WBOYforward
2023-08-24 10:29:021369browse

ES6 (ES2015) 如何演变并为现代 JavaScript 带来新功能?

In this article, you will learn how ES6 (ES2015) evolves and brings new features to modern JavaScript.

ES6 stands for ECMAScript 6. It is the 6th version of ECMAScript and aims to standardize JavaScript. The top ten features of ES6 are: let and const keywords, arrow functions, multi-line strings, default parameters, template literals, destructuring assignment, enhanced object literals, and Promise.

Example 1

In this example, we demonstrate the arrow function (=>) -

console.log("An Arrow function Square has been defined")

square = (x) => { return x * x; }
 
let inputValue = 6
console.log("The input value is defined as :", inputValue)

let result= square(inputValue)
console.log("The square of the given value is :", result)

illustrate

  • Step 1 - Define an arrow function "square" that accepts a number as a parameter and returns the square of that number.

  • Step 2 - Call the function and assign the function call to a value: "result";

  • Step 3 - Display the results.

Example 2

console.log("A class Rectangle is defined that uses constructor ",)
class Rectangle { 
   constructor(x, y) {
      this.x = x;
      this.y = y;
   }
}
let object = new Rectangle(10, 20);
console.log("A sides of the rectangle are defined as ")
console.log(object.x, " and ",object.y)

illustrate

  • Step 1 - Define a "rectangle" class that accepts two numbers as parameters. This class uses a constructor to assign two values.

  • Step 2 - Call the class using the object.

  • Step 3 - Display the value.

The above is the detailed content of How does ES6 (ES2015) evolve and bring new features to modern JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete