2nd Theoretical Class: JavaScript Essentials for React
Variable declarations
Use only if necessary => Use .
Don't use !
Template literals
Strings delimited with (backticks) allowing for multi-line strings and string interpolation
- can contain any expression
Destructuring
Unpack properties from an object or items from an array into constants.
Object destructuring
Useful features of this syntax:
- rename destructured properties
- set default values of properties which are undefined
Array destructuring
Rest & Spread operator ()
The operator can collect or expand values.
Expanding (spread)
Collecting (rest)
Optional chaining
Access a property of an object which is or
Arrow function
An alternative way of declaring a function
Arrow functions are useful for passing anonymous callback functions - see below.
Array method
Transform each element in an array using a callback function
- a new array is created and the original array is not modified
Module imports/exports
Ways to split your application into smaller modules
Default import
- only one default import in a file
- imported name can be anything
Named imports
- multiple imports in one file
- imported name is always the same as the exported name