Chapter 2 Flashcards
(35 cards)
What are examples of ES6 module-loading?
import and `script type=”module”
Module:
a collection of state and publicly exposed methods to operate on that state
Delimit:
surround, separate, define
what are the two forms of values in JS?
primitives and objects
what are the primitive value types in JS?
strings, numbers, symbols, booleans, null, undefined
in JS what is better to use for empty values and why?
undefined; because undefined === undefined but null is an object and has some hidden complexity
what are object values?
objects, arrays and functions
In what ways can typeof be unreliable?
null returns "object" function returns "function" but array returns "object"
Coercion:
converting one value type to another
what is the difference between let and var?
var has function scoping; let uses block scoping
function declaration example
function myFunDeclaration() { }
function expression example
let myFunExpresion = function() { }
what does the === operator do?
disallows type coercion
when does the === operator lie?
NaN and -0
ie:
-0 === 0 // true
NaN === NaN // false
that is the difference in strict operand (===) equality checks for primitives and for objects?
for primitives, it uses structural equality — checking the value or content is the same; for objects, it uses identity equality —checking the reference is the same
what should we start calling the == operator?
coercive equality
what types does == prefer to compare via coercion?
primitive number types
what are the relational operators in js?
> ,=, <=
how do relational operators work
they use numeric comparisons except for when both values are strings, in which case they will use an alphabetical comparison
var x = "10"; var y ="9"; x < y;
true
relational operators use numeric comparisons except for when both values are strings, in which case they will use an alphabetical comparison
What are the two major ways of organizing js code?
classes and modules
Class:
a definition of a type of custom data structure that defines how such a data structure works.
To get a concrete value that you can use, you must instantiate it with the new keyword
How do you define a class?
class Animal { constructor (name, sound) { this.name = name; this.sound = sound; }
speak() { console.log(this.sound); } }
class Zoo { constructor () { this.animals = []; }
addAnimal(name, sound) { const animal = new Animal(name, sound); this.animals.push(animal); }
greet() { this.animals.forEach((animal) => { animal.speak(); }); } }
const greatCanadianZoo = new Zoo();
greatCanadianZoo.addAnimal(‘tiger’, ‘RAWR’);
greatCanadianZoo.greet();
What does polymorphism in regards to classes mean?
that both inherited and overridden methods can have the same name and co-exist