Home >Web Front-end >JS Tutorial >Introduction to let and const in ES6

Introduction to let and const in ES6

零下一度
零下一度Original
2017-06-26 09:26:381315browse

The contents written in this series of blogs are some summaries of my daily studies. They are used as notes and review. If there is something wrong, please point it out, thank you Nonsense Without further ado, let’s get started!

Both let and const can be used to define variables (similar to var), but there are some differences and new features. As shown below

1. let command( is used to declare variables)

 1 . Since there is no block-level scope in js, variables declared by let are only valid within the block to which they belong and cannot be accessed externally. (For example, anything within a pair of braces can be understood as a block-level scope)

 2. Use es6 syntax to adopt strict mode by default, and undeclared variable references in strict mode An error will be reported

3. You cannot declare the same variable repeatedly using let

2. Const command (Define a constant

 1. Constants declared using const cannot be modified (if a reference type (object) is declared, the pointer cannot be changed, but the content inside can be modified. Modified)

2. const also has a block-level scope like let

3. const declaration Must be assigned

 

The above is the detailed content of Introduction to let and const in ES6. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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
Previous article:How is this used?Next article:How is this used?