1. JavaScript¶
JavaScript can function as both a procedural and an object oriented language.
Web browser is the runtime environment for client-side JavaScript.
Node.js is a server side environment that is operates in a similar capacity to the JVM in java
1.1. JavaScript vs ECMAScript¶
ECMAScript/ESis a specification for a scripting language.- Not all browsers support all ES features
2. Printout¶
3. Variable declaration and definition¶
JavaScript is dynamically-typed and does not require type constraints
There are 3 keywords for declaration:
var- was default before ES6. But due to issues, that's why there are other ways of declaring.- Scope: Declared global outside function. And local when declared inside the function.
- var variables can be re-declared and updated
- Hoisting of var: if var is referred to before declaration. Then interpreter assumes it was assigned to
undefined - The problem is that var can be redefined in the middle of the code, which can cause unexpected answers.
let- now used as the preferred variable declaration.- Block scoped: (A block lives in curly braces)
- Can be updated but not re-declared
- Those two can be combined, by redeclaring variables in blocks.
- Hoisting of let: Just like
varit can be hoisted on the top, but unlikevaryou getReference Error
const- maintain constant values- Block Scoped: can only be accessed within the block they were declared
- Cannot be updated or re-declared: Therefore it's constant
- For a constant object, the object cannot be updated or redefined but the properties can be changed.
- Hoisting of const: Hoisted but no initialised just like let
4. Access modifiers¶
There are no access modifiers like in Java, everything is accessible.
5. Primitive Types in JavaScript¶
Number- equivalent todoublein JavaString- no such thing as acharBooleanSymbol- ES6 additionUndefined- implicitly assigned when variable is declared but not instantiatedNull- Is an explicitly assigned.