Question | Answer |
whats the diff between let and var | let is scoped to the code block var is scoped to the function block use let |
4 rules for variable names` | cant be reserved should be meaning cant start with number cant have space or - |
variable types | primitives and referenct types |
primitive types | string numbers boolean undefined null |
undefined type | all vars set by default |
dynamic typing | the types can change with use |
what is special about undefined | its a type and a value |
reference types | object array function |
example of object literal | let person = {} |
make a person object | let person = { name: 'test', age: 44 }; |
accessing an objects props 2 types and examepls | dot notation and bracket notation person.name person['name'] |
why use bracket notiation | when you dont know the name of the property at dev, but only at runtime |
example of an array literal | let selectedColors = []; |
what does === mean | strict equality compare type and value |
what does == mean, and how does it do it? | loose quality, just compare values, not types so 1 is the same as '1' it takes the type on left, converts the type on right and then does === |
example of ternary | let type = pts > 100 ? 'true result' : 'false result' |
logical operator and non bool | this is when you try to compare diff types of values |
Falsy values | false 0 '' or "" null undefined NaN |
example of switch | let role; switch (role) { case "test": { console.log("sd"); break; } default: { console.log("sdss"); } } |
for in loop | this is to view the props of an object for (let key in someobject) { console.log(key); } |
diff between : and = | : is for Literal Notiation, for key value pairs { name : 'test' } this is a shortcut just for object literal notations = is for Assignment name = 'test' |
what is hoisting | when js runs, it takes all the f declarations and moves them to the top. thats why you can run a declared function before its defined. |
what is 'this' | its the object thats executing the current function |
4 pillars of OOP | encapsulation abstraction inheritance polymorphism |
encapsulation | increase usablity group related data and funcs into a unit and then ref that unit when needed this is an object with Properties and methods |
simple diff between oop and procedural | procedural has funcs with lots of params, its how the data gets in Opp creates objects with minimal or no params, so that you just have to call the func, and it has access to the props in the object |
abstraction | simplify the interface to O, hide complexity reduces the impact of change because the use is simple |
inheritance | by creating base O, you can create objects based on that baseO that dont have to have all the dup methods and props. |
polymorphism | many forms a bunch of objects, might have the same func render(), but each of them will do it differently. but all will have a render() |
what is closure | its the scoping of properties to inside methods, |
How do you do oop with classic JS? when there are no classes | prototypes a proto is a parent object |
how does JS engine search for a method or prop | starts with the current obj, and if it cant find it, it will crawl up the proto chain until it finds it |
Want to create your own Flashcards for free with GoConqr? Learn more.