Home > Web Front-end > JS Tutorial > 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
Release: 2023-08-24 10:29:02
forward
1410 people have browsed it

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)
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template