Task 1: Introduction
- Rhyme: cloud learning system, splite screen to workspace(desktop) and video;
- nodemon -> browser-sync;
- npx: execute bin file as node dependencies.
- Q: Difference between npm and npx?
- A: Npm is a tool that use to install packages. Npx is a tool that use to execute packages.
Task 2: Variable (let) and Scoping
var:
- redeclarable
- only function-scope, but no block-scope: var defined inside a for-loop could be used outside the loop.
| a | console.log(hi); | ReferenceError: hi is not defined; |
| b | var hi; console.log(hi); | undefined; |
| c | console.log(hi); var hi; | undefined; 1. variables and functions in JS are hoisted; 2. var are initialized to undefined; |
let:
- not redeclarable
- both function-scope and block-scope
| a | console.log(hi); | ReferenceError: hi is not defined; |
| b | let hi; console.log(hi); | undefined; |
| c | console.log(hi); let hi; | ReferenceError: hi is not defined; hoisted but not initialized as undefined(?); |
- Hoisting in JS: [Ref: MDN Hoisting]
- A strict definition of hoisting suggests that variable and function declarations are physically moved to the top of your code.
- JavaScript only hoists declarations, not initializations. If a variable is declared and initialized after using it, the value will be undefined.