Mobile App Development With React Native
Mobile App Development With React Native
// hi I'm a comment
for (let i = 0; i < arr.length; i++) {
console.log(arr[i]);
}
Types
● Dynamic typing
● Primitive types (no methods, immutable)
○ undefined
○ null
○ boolean
○ number
○ string
○ (symbol)
● Objects
Typecasting? Coercion.
● Explicit vs. Implicit coercion
○ const x = 42;
○ const explicit = String(x); // explicit === "42"
○ const implicit = x + ""; // implicit === "42"
● == vs. ===
○ == coerces the types
○ === requires equivalent types
https://github.com/dorey/JavaScript-Equality-Table
Coercion, cont.
● Which values are falsy?
○ undefined
○ null
○ false
○ +0, -0, NaN
○ ""
42.toString() // Errors
const x = 42;
x.toString() // "42"
x.__proto__ // [Number: 0]
x instanceof Number // false
Prototypal Inheritance
● Why use reference to prototype?
● What’s the alternative?
● What’s the danger?
Scope
● Variable lifetime
○ Lexical scoping (var): from when they’re declared until when their
function ends
○ Block scoping (const, let): until the next } is reached
● Hoisting
○ Function definitions are hoisted, but not lexically-scoped initializations
● But how/why?
The JavaScript Engine
● Before executing the code, the engine reads the entire file
and will throw a syntax error if one is found
○ Any function definitions will be saved in memory
○ Variable initializations will not be run, but lexically-scoped variable names
will be declared
The Global Object
● All variables and functions are actually parameters and
methods on the global object
○ Browser global object is the `window` object
○ Node.js global object is the `global` object