Javascript Flashcards

1
Q

Write:

How to include a javascript file?

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

Is JS a dynamic language?

If so, what does that entail?

A

It is a dynamic language. As such, the value of the variables can be modified at runtime

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

What are the three ways to declare variables?

A

let, var and const

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

What happens if a variable is created without being declared?

A

They are global

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

What happened if a variable is not assigned a value?

A

Its value is “undefined”

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

What is a Falsy value?

What are the falsy values?

A

A value that is not false, but would be false in a Boolean context

undefined, NaN, null, “”, 0

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

What happens if we try to + a string and a number?

A

The number is coerced to a string.

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

What are the five primitive data types in JS?

A

Number, String, Boolean, null and undefined

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

What are the comparison rules for < and >

A

1-If one is a number and the other can be converted: comparison
2-If one is a number and the other one cannot be converted: false
3-If both are strings: string comparison

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

What are the comparison rules for all the other operators (asterisk, /, %)

A

If one cannot be converted to a number: NaN

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

What are the two types of equality operators, and how do they differ?

A

The loose equality (==, !=) and the strict equality (===, !==). The former does type coercion, the latter does not

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

For the variable declarator “let”, tell us about its scope, whether it can be redeclared and whether a value must be declared at creation.

A

Block scope, cannot be redeclared and does not have to be assigned a value at declaration

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

For the variable declarator “const”, tell us about its scope, whether it can be redeclared and whether a value must be declared at creation.

A

Block scope, cannot be redeclared and must be assigned a value at declaration

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

For the variable declarator “var”, tell us about its scope, whether it can be redeclared and whether a value must be declared at creation.

A

Global scope, can be redeclared and can also be declared before use

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

How to traverse all properties in an object?

A

for (x in object){…}

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

How to create an object?

A

var object = new Object();

17
Q

Write

What are the two ways to create properties in an object?

A

either myobj.prop1=… or var myobj={prop1: …, prop2:…};

18
Q

Write

What are the two ways to create arrays?

A

var myArray = [1, 2, 3]
var myArray = new Array(1,2,”3”)

19
Q

What does .join do on an Array?

A

Array.join(“;”) for example, separates all the elements of the array by ; and returns it

20
Q

What does Array.toString() do?

A

It concatenates the array and separates it with commas (like .join(“,”) would)

21
Q

What does .slice() do?

A

It cuts a part of the array, from the first integer (inclusive) to the second integer (exclusive)

22
Q

What is the difference between actual parameters and formal parameters?

A

Formal parameters are those written in the function creation while actual parameters are those used in the function call

23
Q

Write

A sorting function to sort numbers, as well as its call

A

function sortNumber(a,b){
return a-b;
}
document.write(array.sort(sortNumber));

24
Q

Write

How to write an anonymous function?

A

var f = function (a,b) {return a-b};

25
Q

What happens if the prototype of an object is modified?

A

It changes the template of all objects of this type

26
Q

Write

A constructor for a car object and the subsequent creation of a car object.

A

function car(make, year, model) {
this.make=make;
this.year=year;
this.model=model;
}

let car1 = new car(“Ford”, “2017”, “Fiesta”);

27
Q

Write

For the car constructor, write a display function and add it to the constructor

A

function displayCar(){
document.write(“Year: “+this.year);}

this.display=displayCar; (to add to the constructor, since functions can be passed as parameters)