intro to Javascript Flashcards

1
Q

let name = null:

TYPEOF//

A

object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

3 reference types

A

objects
arrays
funtions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

let colors = {“blue, “green’}

typeof colors

A

object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

function greet (name){

console.log(“hello” + name)
}

name is called a ____

A

parameter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

default value of variables

A

undefined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

an EXPRESSION produces __

A

a value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
let x = 10
console.log(++x)//

console.log(x)

A

11

11

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
let x = 10
console.log(x++)//

console.log(x)

A

10

11

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

‘1’ === 1

A

false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

strict operator compares _____ and ______

A

value and type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

false || 1 || 2

A

1

operators go from left to right

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

two types of conditional statements

A

if…else

switch

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

when we need to repeat code we use ________

A

loops

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

name all the loops

A
for
while
do...while
for...in
for...of
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

let i = 0;

while (i <=10) {
  if (i % 2 === 0){
  i++;
 continue;
}

console.log(i);
i++;
}

RETURNS?

A
1
3
5
7
9
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

SHORTEN THIS

function isLandscape (width, height){
return (width > height) ? true : false;
}
A
function isLandscape (width, height){
return (width > height);
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

instead of writing “Not a number” you can use ___

A

NaN

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

typeof NaN //

A

number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

In JavaScript, any function can return a new object. When it’s not a constructor function or class, it’s called a __________

A

factory function.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

IN MODERN JS WHAT CAN BE CHANGED?

function createCircle(radius){
 return {
    radius: radius, 
   draw: function (){
       console.log('draw')
       }
  };

}

A

make “radius: radius” to just “radius,:”

+++++++++

draw: (){
console.log(‘draw’)
}
};

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q
function createCircle(radius){
 return {
    radius: radius, 
   draw: (){
       console.log('draw')
       }
  };
}

create a new circle with radius of 14

A

let circle1 = createCircle(14)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

what is Pascal notation?

A

when the first letter of every word is capitalized used in creating constructor functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

in JS a factory function uses the keyword _____ to create an object

A

return

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q
function Circle(radius){
this.radius = radius;

}

ADD A DRAW FUNCTION

A

this.draw = function (){

}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

when making a object from a constuctor function use the _____ keyword

A

new

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

when you use the new keyword with a constuctor function 3 things happen

A
  1. JS creates empty object
  2. sets “this” to point to new empty object
  3. new operator return a this new object from the function “return this”
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

what uses “this” keyword

  1. factory functions
  2. constructor functions
A

constructor functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

what uses the “return” keyword to create a new object

  1. factory functions
  2. constructor functions
A

factory functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

when we use Const on a object we can not reassign the name

TRUE / FALSE

A

TRUE

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

DELETE RADIUS

const circle = {
    radius: 1
}

console.log(circle)

A

delete circle.radius;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

every object in JS has a property called _______

A

constuctor

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

a constructor references

A

the function that was used to construct an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q
function Circle(radius) {
     this.radius = radius;
}

const another = new Circle(1)

CREATE NEW OBJECT USING .CALL() METHOD

A

Circle.call({}, 1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

“THIS” REFERS TO WHAT AND WHY?

function Circle(radius) {
     this.radius = radius;
}

const another = new Circle(1)

A

The object being created

uses new keyword when creating new obect

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

“THIS” REFERS TO WHAT AND WHY?

function Circle(radius) {
     this.radius = radius;
}

const another = Circle(1)

A

Global object which is window

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q
function Circle(radius) {
     this.radius = radius;
}

const another = new Circle(1)

CREATE NEW OBJECT USING .CALL() METHOD POINTING TO WINDWO

A

Circle.call(window, 1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

In JS functions are objects

TRUE / FALSE

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q
let x = 10
let y = x

x = 20

x?
y?

A

20

10

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q
let x = {value: 10};
let y = x;

x.value = 20;

x?
y?

A

{value: 20}

{value: 20}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

primitives are copied by their ______

objects are copied by their ________

A

value

reference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

_______ are copied by their value

_______ are copied by their reference

A

primitives

objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

let number = 10;

function increase(number){
number++;
}

increase(number); //?
WHY?

A

10

we are dealing with let number at 10;

not in scope of function as primitives copied by value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

let obj = {value: 10};

function increase(obj){
obj.value++;
}

console.log(increase(obj)); //?

A

11

objects copied by reference

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q
const circle = {
radius: 1,
color: 'blue'
}

iterate to get keys

A

for (let key in circle)

console.log(key)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q
const circle = {
radius: 1,
color: 'blue'
}

iterate to get values

A

for (let key in circle)

console.log(circle[key])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

Object is or is not iterable

A

NOT

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q
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

A

for (let key of Object.keys(circle))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

const x = {value : 1};

this is a call to what function?

A

function Object() {}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q
const circle = {
radius: 1,
color: 'blue'
}

using FOR…OF iterate a OBJECT (even though for of is not the best way ) to get the values

A

for (let key of Object.entires(circle))

50
Q
const circle = {
radius: 1,
color: 'blue'
}

CHECK TO SEE IF RADIUS IS IN CIRCLE

A

if (‘radius’ in circle) // code

51
Q

an iterable ways to clone an object

A

for…in

52
Q

for modern JS to copy an object is _______

A

object.assign()

53
Q

a more modern way to doing this is

const another = {};
for (let key in obj)
another[key] = circle[key]
A

const another = object.assign

54
Q

clone circle using SPREAD operator

const circle = {
radius: 1,
color: 'blue'
}
A

const obj = {…circle};

55
Q
const circle = {
radius: 1,
}

const obj =

USING OBJECT.ASSIGN CLONE OBJECT ADD COLOR

A

const obj = Object.assign({color: “yellow”}, circle)

56
Q

_______ types don’t have methods only objects

some examples

A

primitives

string, number, boolean….

57
Q
const message = "hi";
const another = new String('hi');

console. log(typeof another); //
console. log(typeof message); //

A

object

string

58
Q
const message = "hi"; 
there are methods on the above because JS creates a sting \_\_\_\_\_\_\_\_\_\_
A

wrapper

59
Q
let address1 = new Address ('a','b', 'c');
let address2 = new Address ('a','b', 'c');
let address3 = address1;

console. log(areEqual(address1, address3));
console. log(areEqual(address1, address2));
console. log(areSame(address1, address2));
console. log(areSame(address1, address3));
console. log(areSame(address2, address3));

function Address (street, address, zip){
    this.street = street;
    this.address = address;
    this.zip = zip;
}

function areEqual(address1, address2){
return address1.street === address2.street &&
address1.address === address2.address &&
address1.zip === address2.zip
}

function areSame(address1, address2){
    return address1 === address2;

}

A
true
true
false
true
false
60
Q

when you have nested loops, one way to clean up the code is too ________

A

break up the code in different functions and pass along the function

61
Q

a another name for call back functions is a _________ function

A

predicate

62
Q

Turn into a arrow funtion

courses.find(function(course){
return course.name === ‘a’
});

A

courses.find(course=>course.name === ‘a’)

63
Q

with an arrow function if you have no parameters you must use an

A

empty set of parathenthases

64
Q

const numbers = [1,2,3,4];

4 WAYS TO CLEAR ARRAY

A

numbers = [];

numbers. length = 0;
numbers. splice(0, numbers.length);

while (numbers.length > 0)
numbers.pop();

65
Q
const numbers = [1,2,3,4];
let another = numbers
number = []

console. log(another);
console. log(numbers);

A

[1,2,3,4]

[1,2,3,4]

66
Q
const first = [1,2,3];
const second =[4,5,6];
const third = first.concat(second);
// write using spread operator
A

const third = […first, …second];

67
Q

2 main ways to iterate an array

A

for…of

forEach()

68
Q

what type of function uses a semicolon to end ?

A

function expression

69
Q
let run = function (){
    console.log("run")
};

// attach the varibable move to run

run()
move();

A

let move = run;

DONT use () at the end. we are not calling the function.

70
Q

What is hoisting in JS?

A

is the process of moving function declarations to the top of the program

71
Q
function sum (a, b){
return a + b
}

sum(1) // returns

A

NAN

1 + undefined = NAN

72
Q

the rest operator is associated with _____

A

function parameters

73
Q

The spread operator is associated with ______

A

Arrays

74
Q
function sum(...arg){
console.log(arg);
};

console. log(sum(1,2)); // ?
console. log(sum(1,2,3)); // ?

A

array [1,2]

array [1,2,3]

75
Q
function sum(arg){
console.log(arg);
};

console. log(sum(1,2)); // ?
console. log(sum(1,2,3)); // ?

A

1

1

76
Q
function rates(price, years) {
price = price || 3.5
years = years || 10
}

REWRITE TO DEFAULT VALUES

A
function rates(price = 3.5, years = 10) {
}
77
Q
function rate(principle, rates = 3.5, years) {
return = principle + rates + years;
}

rate(1000, 5) returns?

A

NAN

JS does not know what to assign 5 too.

78
Q
function rate(principle, rates = 3.5, years) {
return = principle + rates + years;
}

rate(1000, 5) returns an error. How to avoid

A

use “UNDEFINED” in the arguements

79
Q
const person = {
first: "steve"
last: "me"
fullName: function () {code} // WRITE SHORTER WAY
}
A

fullName(){}

drop function keyword inside an object in ES 6

80
Q

We use ________ to access properties in an object

A

getters

81
Q

we use _________ to change or mutate properties

A

setters

82
Q

getters

A

to access properties in an object

83
Q

setters

A

to change or mutate properties

84
Q

in order to alter properties of an object from the outside we must have a __________

A

setter

85
Q

When you have a getter in an object you can drop the _______ when you call it

A

the ()

86
Q

defensive programing (try and catch) should be done when?

A

start of the function

87
Q

to catch a error use the ______ constructor function

A

throw new error()

88
Q

the ________ word is associated with the throw keyword

A

exception

89
Q

the 3 keywords associted with checking a value

A

throw, catch, try

90
Q
{
   const message = "hello";
}

console.log(message); // ?

A

error

91
Q
{
    var message = "helloVar";
}

console.log(message);

A

helloVar

92
Q

_____ and ______ are limited to the block they are defeined

A

let

const

93
Q

______ variables in a function take precedence over ______ varibales

A

local

global

94
Q
function loop (){
for (let i = 0; i < 5; i++){
    console.log(i);
    }
}

loop();

A

0 1 2 3 4

95
Q
function loop (){
for (let i = 0; i < 5; i++){
    }
    console.log(i);
}

loop();

A

error

i is let and outside scope

96
Q
function loop (){
for (var i = 0; i < 5; i++)
    console.log(i);
    console.log(i);
}

loop();

A

0 1 2 3 4 5

97
Q
function loop (){
for (let i = 0; i < 5; i++)
    console.log(i);
    console.log(i);
}

loop();

A

0 1 2 3 4
error
let uses the line first code as a block

98
Q

var scope is or is not limited to block it’s defined but to the ______ its defined

A

NOT

function

99
Q

var creates block-scope or function scope variables?

A

function scope

100
Q

let creates block-scope or function scope variables?

A

block-scope

101
Q

const creates block-scope or function scope variables?

A

block-scope

102
Q
function loop (){
for (var i = 0; i < 5; i++){
    if (true){
        var color = red;
    }
}
 }

Is color accessible anywhere in the function?

A

yes because it’s var and it uses function scope.

103
Q
function loop (){
for (var i = 0; i < 5; i++){
    if (true){
        let color = red;
    }
}
 }

Is color accessible anywhere in the function?

A

no because it’s let and only uses block scope

104
Q
var color = "blue";
let age = 44;

window. color// ?
window. age // ?

A

blue - uses var and attached to window object

undefind -

105
Q
function  sayHi(){
code //
}

TRUE / FALSE
it the above attached to the window object?

A

true

106
Q

What is “this” in JS?

A

the object that is executing the current function

107
Q

if function a part of object called a method “this” references ____

A

the object itself

108
Q

if function is not party of an object “this” references ____

A

the global object

109
Q
const video = {
    title: "a",
    play (){
        console.log(this);
    }
}

video.play();

A

the video object

{title: “a”, play: ƒ}

110
Q
const video = {
    title: "a",
    play (){
        console.log(this);
    }
};

video.stop = function (){
console.log(this);
}

video.stop();

A

the video object

{title: “a”, play: ƒ, stop ƒ}

111
Q

function playVideo(){
console.log(this);
}
playVideo();

A

the window object

112
Q
function Video(title){
  this.title = title;
  console.log(this);
}

const v = new Video(“a”);

A

Video{title: “a”}

constructor function creates new function and points this to object and returns object

113
Q
const video = {
    title: "a",
    tags: ["a", "b", "c"],
    showtags (){
        this.tags.forEach(function(tag){
            console.log(tag);
        });
    }
};

video.showtags(); // returns?

A

a, b, c

114
Q
const video = {
    title: "a",
    tags: ["a", "b", "c"],
    showtags (){
        this.tags.forEach(function(tag){
            console.log(this);
        });
    }
};

video.showtags(); // returns?

A

Window Object

Window Object

Window Object

the callback function is a regular function and it’s references global object (window)

115
Q
function playVideo(){
    console.log(this);
}

playVideo.call({name: “me”});
playVideo();

A

// {name: “me”};

// window object

116
Q
function playVideo(){
    console.log(this);
}

playVideo.call({name: “me”}); //
playVideo.apply({name: “me”}); //

A

// {name: “me”};

// {name: “me”};

117
Q

with the apply method the arguments must be passed at an ________ .

A

array

118
Q

with the call method the arguments must be passed at an ________ .

A

sting with comma

119
Q

Call, apply, bind.

WHAT RETURNS a NEW FUNCTION?

A

Bind

120
Q
function playVideo(){
    console.log(this);
}

playVideo.bind({name: “me”})(); //returns

A

// {name: “me”};

121
Q

call(), apply (), bind() returns a function, which can be executed at a later time

https://www.hacksparrow.com/javascript/bind-vs-apply-vs-call.html

A

bind()