intro to Javascript Flashcards
let name = null:
TYPEOF//
object
3 reference types
objects
arrays
funtions
let colors = {“blue, “green’}
typeof colors
object
function greet (name){
console.log(“hello” + name)
}
name is called a ____
parameter
default value of variables
undefined
an EXPRESSION produces __
a value
let x = 10 console.log(++x)//
console.log(x)
11
11
let x = 10 console.log(x++)//
console.log(x)
10
11
‘1’ === 1
false
strict operator compares _____ and ______
value and type
false || 1 || 2
1
operators go from left to right
two types of conditional statements
if…else
switch
when we need to repeat code we use ________
loops
name all the loops
for while do...while for...in for...of
let i = 0;
while (i <=10) { if (i % 2 === 0){ i++; continue; }
console.log(i);
i++;
}
RETURNS?
1 3 5 7 9
SHORTEN THIS
function isLandscape (width, height){ return (width > height) ? true : false; }
function isLandscape (width, height){ return (width > height); }
instead of writing “Not a number” you can use ___
NaN
typeof NaN //
number
In JavaScript, any function can return a new object. When it’s not a constructor function or class, it’s called a __________
factory function.
IN MODERN JS WHAT CAN BE CHANGED?
function createCircle(radius){ return { radius: radius, draw: function (){ console.log('draw') } };
}
make “radius: radius” to just “radius,:”
+++++++++
draw: (){
console.log(‘draw’)
}
};
function createCircle(radius){ return { radius: radius, draw: (){ console.log('draw') } }; }
create a new circle with radius of 14
let circle1 = createCircle(14)
what is Pascal notation?
when the first letter of every word is capitalized used in creating constructor functions
in JS a factory function uses the keyword _____ to create an object
return
function Circle(radius){ this.radius = radius;
}
ADD A DRAW FUNCTION
this.draw = function (){
}
when making a object from a constuctor function use the _____ keyword
new
when you use the new keyword with a constuctor function 3 things happen
- JS creates empty object
- sets “this” to point to new empty object
- new operator return a this new object from the function “return this”
what uses “this” keyword
- factory functions
- constructor functions
constructor functions
what uses the “return” keyword to create a new object
- factory functions
- constructor functions
factory functions
when we use Const on a object we can not reassign the name
TRUE / FALSE
TRUE
DELETE RADIUS
const circle = { radius: 1 }
console.log(circle)
delete circle.radius;
every object in JS has a property called _______
constuctor
a constructor references
the function that was used to construct an object.
function Circle(radius) { this.radius = radius; }
const another = new Circle(1)
CREATE NEW OBJECT USING .CALL() METHOD
Circle.call({}, 1)
“THIS” REFERS TO WHAT AND WHY?
function Circle(radius) { this.radius = radius; }
const another = new Circle(1)
The object being created
uses new keyword when creating new obect
“THIS” REFERS TO WHAT AND WHY?
function Circle(radius) { this.radius = radius; }
const another = Circle(1)
Global object which is window
function Circle(radius) { this.radius = radius; }
const another = new Circle(1)
CREATE NEW OBJECT USING .CALL() METHOD POINTING TO WINDWO
Circle.call(window, 1)
In JS functions are objects
TRUE / FALSE
true
let x = 10 let y = x
x = 20
x?
y?
20
10
let x = {value: 10}; let y = x;
x.value = 20;
x?
y?
{value: 20}
{value: 20}
primitives are copied by their ______
objects are copied by their ________
value
reference
_______ are copied by their value
_______ are copied by their reference
primitives
objects
let number = 10;
function increase(number){ number++; }
increase(number); //?
WHY?
10
we are dealing with let number at 10;
not in scope of function as primitives copied by value
let obj = {value: 10};
function increase(obj){ obj.value++; }
console.log(increase(obj)); //?
11
objects copied by reference
const circle = { radius: 1, color: 'blue' }
iterate to get keys
for (let key in circle)
console.log(key)
const circle = { radius: 1, color: 'blue' }
iterate to get values
for (let key in circle)
console.log(circle[key])
Object is or is not iterable
NOT
const circle = { radius: 1, color: 'blue' }
using FOR…OF iterate a OBJECT (even though for of is not the best way ) to get the keys
for (let key of Object.keys(circle))
const x = {value : 1};
this is a call to what function?
function Object() {}