Mid Term study Javascript types Flashcards

1
Q

The two types of variables and when to use them?

A

let and const

let is used for variables whose value changes during runtime
const is used for variables whose value never changes during runtime

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

What are the 6 Primitive Types in Javascript

A

Number, BigInt, String, Boolean, null(empty), undefined(value not assigned)

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

What are the non-Primitive types in Javascript?

A

Objects: coded using {}
Symbols

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

How do parseInt() and parseFloat() work in javascript?

A

both read digits from a string until they can’t read any more digits

Example:

parseInt(“16px”) will stop before p

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

How to
1.Convert String to numbers

2.Convert things to String

A

1.parseInt(), parseFloat(), Number()

2.String()

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

What does this output?

console.log(“5” / “2”);
console.log(5 / 2);
console.log(“5” / 2);

A

2.5
2.5
2.5

Javascript does implicit conversion in this case

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

How to:
Convert to Booleans

A

Boolean() or !!thingtoconvert

example: console.log(!!n);

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

What is the output?

console.log(Number(undefined));
console.log(Number(true));
console.log(Number(false));
console.log(Number(null));
console.log(Number(“ 1234abc”));
console.log(Number(“ “));

A

console.log(Number(undefined)); = NaN
console.log(Number(true)); = 1
console.log(Number(false)); = 0
console.log(Number(null)); = 0
console.log(Number(“ 1234abc”)); = NaN
console.log(Number(“ “)); = 0

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

What is the output?

console.log(Boolean(0));
console.log(Boolean(1));
console.log(Boolean(null));
console.log(Boolean(undefined));
console.log(Boolean(NaN));
console.log(Boolean(“foo”));
console.log(Boolean(25));

A

console.log(Boolean(0)); = false
console.log(Boolean(1)); = true
console.log(Boolean(null)); = false
console.log(Boolean(undefined)); = false
console.log(Boolean(NaN)); = false
console.log(Boolean(“foo”)); = true
console.log(Boolean(25)); = true

non 0 values will be true
0 and error types will be false

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