1/56
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Data types
Primitive: string, bigint, undefined, null, symbol, boolean, number
Non-primitive: object
undefined vs null
Undefined: declared but not intialized, no function return
Null: deliberate absence of val, removes ref
hoisting
default JS behaviour where all var and func declarations are moved on top of the scope
debugger
adding this word to the code will trigger the browser’s debugger
‘==’ vs ‘===’
loose equality (==): makes type coercion
strict equality (===): compares values and types
var x = 2, y = "2";
(x == y) //true
(x === y) //false
type coercion
automatic conversion from one data type to another
string coercion
number + string: turns number to string
number - string: turns string into number
var x = 3;
var y = "3";
x + y // Returns "33"
x - y // Returns 0
falsy/truthy values
truthy vals will be coerced to true, falsy to false
falsy: false, 0, 0n, -0, ““, null, undefined, NaN
truthy: the rest
boolean coercion
if statements: will run if truthy
logical operators: returns one of the operands
OR: if first truthy, returns first. otherwise, returns second
AND: if both truthy, returns second. if one falsy, returns it
var x = 220;
var y = "Hello";
var z = undefined;
x | | y // Returns 220
x | | z // Returns 220
x && y // Returns "Hello"
y && z // Returns undefined
if( x && y ){
console.log("Code runs" ); // This block runs
}
if( x || z ){
console.log("Code runs"); // This block runs
}
var vs let
let was added later
var has function scope, let has block scope
JS scopes
JS is ___ typed
Dynamically/loosely
var type is checked at runtime
var can hold any data type
NaN property
Not-A-Number
val that isnt a legal number
isNaN("Hello") // true
isNaN(345) // false
isNaN('1') // false, since '1' is converted to Number type which results in 0 ( a number)
isNaN(true) // false, since true converted to Number type results in 1 ( a number)
isNaN(false) // false
isNaN(undefined) // true
passed by value
passing a primitive var to another var will only pass the value
a new reference is created and receives value
var y = #8454; // y pointing to address of the value 234
var z = y;
var z = #5411; // z pointing to a completely new address of the value 234
// Changing the value of y
y = 23;
console.log(z); // Returns 234, since z points to a new address in the memory so changes in y will not effect z
passed by reference
passing a non-primitive var to another var passes the reference
var obj = #8711; // obj pointing to address of { name: "Vivek", surname: "Bisht" }
var obj2 = obj;
var obj2 = #8711; // obj2 pointing to the same address
// changing the value of obj1
obj.name = "Akki";
console.log(obj2);
// Returns {name:"Akki", surname:"Bisht"} since both the variables are pointing to the same address.
IIFE
Inmediately Invoked Function
a function that runs as soon as it is defined
(function(){
// Do something;
})();
JS strict mode