New ES6 features

New ES6 features

Welcome to wechat public account [front-end gongcheng House] to share some front-end technology, interview questions, interview skills and so on

Variable declaration:constlet

  • Compared to the previousvarNo matter where the declaration is, it is considered to be declared at the top of the function
  • letRepresents the declaration of variables, andconstRepresents a declaration constant.
  • Both are block-level scopes
  • Does not have the variable promotion feature, the formation of a temporary dead zone, early access to the variable will report an error
  • constMust be assigned when declared

Template string

  • String formatting via backquotes, withThe ${}To implement expression embedding

Arrow function

  • Don’t needfunctionKeyword to create a function
  • omitreturnThe keyword
  • Inheriting from the current contextthisThe keyword
  • If the function is a constructor,thisPointer to a new object
    • Function calls in strict mode,thisPoint to theundefined
    • If the function is a method of an object, thenthisThe pointer points to this object
  • There is noargumentsObject,The remaining parametersIs compared to usingargumentsA better choice of objects
  • You can’t usenewOperator that cannot be used as a constructor
  • There is noprototypeProperties = >undefined

Class class

  • The declaration of a class does not improve if you use aClassIt must be defined before it is used.
  • Defining functions in a class is not requiredfunctionThe keyword

other

  • Parameter Default Value
  • Rest operator.
  • Object array deconstruction
  • for... offor... in
    • for... ofUsed to iterate over an iterator, such as a set of numbers
    • for... inUsed to traverse properties in an object

Hope to read this article you have help, have inspiration, if there is not enough, welcome to criticize the exchange!

Welcome to wechat public account [front-end gongcheng House] to share some front-end technology, interview questions, interview skills and so on

Hard to sort out for a long time, but also hope to manually praise encouragement ~


‘Extract’ is not simply “paste -> copy”, but eye to, hand to, heart to beat down every word.

Statement: all reprinted articles and pictures are only used for the author’s own collection and study purposes. If requested or deemed appropriate, attribution and source will be indicated. If you do not want a work to be re-used, please inform the site in time, the site will be deleted in time.