Ecmascript 6
ES5 –‘use strict’
• Placed at the top of a file
• Executes the browser in ‘strict’ mode
• Easier to write safe javascript
• Feedback on errors
• Remove bad practices
Hoisting principle
Standard behaviour by javascript to place all declarations to the top of the current scope
Let
• New way to declare variables
• Hoisting is not applied
• Easier to detect bad code or errors
No hoisting is applied so teacherSalary is unknown. This does not crash because the code is
executed AFTER the declaration.
,Const
• New way to declare constants
• Hoisting is not applied
• Easier to detect bad code or error
Template Literals
• New and easier way of concatenating strings
• Use the backtick instead of single quotes.
• Backtick: ``
• Single quote: ‘’
Template literal: ${expression}
, Destructuring
Allows the retrieval of values from an array on the left side of the statement.
Object destructuring
Object destructuring function
Destructing the function moveCourse will result in a broken version.
Keyword ‘this’ does not point to the object.
ES5 –‘use strict’
• Placed at the top of a file
• Executes the browser in ‘strict’ mode
• Easier to write safe javascript
• Feedback on errors
• Remove bad practices
Hoisting principle
Standard behaviour by javascript to place all declarations to the top of the current scope
Let
• New way to declare variables
• Hoisting is not applied
• Easier to detect bad code or errors
No hoisting is applied so teacherSalary is unknown. This does not crash because the code is
executed AFTER the declaration.
,Const
• New way to declare constants
• Hoisting is not applied
• Easier to detect bad code or error
Template Literals
• New and easier way of concatenating strings
• Use the backtick instead of single quotes.
• Backtick: ``
• Single quote: ‘’
Template literal: ${expression}
, Destructuring
Allows the retrieval of values from an array on the left side of the statement.
Object destructuring
Object destructuring function
Destructing the function moveCourse will result in a broken version.
Keyword ‘this’ does not point to the object.