Vanilla JS Flashcards

1
Q

How do you create Undefined?

A

let firstName;

console.log(firstName);

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

What does typeof operator do?

A

console. log(typeof ‘Iman Sayah’) // string
console. log(typeof 5) // number
console. log(typeof true) // boolean
console. log(typeof null) // object type
console. log(typeof undefined) // undefined

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

Primitive data types are immutable? Example?

A
let word = "JavaScript"
word[0] = "K"
// error
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are primitive data types in JavaScript?

A

Numbers - Integers, floats
Strings - Any data under single quote, double quote or backtick quote
Booleans - true or false value
Null - empty value or no value
Undefined - a declared variable without a value

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

What are non-primitive data type in JavaScript?

A

Objects
Functions
Arrays

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

Which data types are immutable?

a) primitive
b) non-primitive

A

primitive

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

How do you create a random number between 0 and 0.999999?

A

Math.random()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
Math.round()
Math.floor()
Math.ceil()
Math.min()
Math.max()
A
round to nearest int
round down to nearset int
round up to nearest int
min of a list of values: Math.min(1,2,3)
max of a list of values: Math.max(1,2,3)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How do you generate a number between 0 and 10?

A
let randomNum = Math.random()                     // generates 0 to 0.999
let numBtnZeroAndTen = randomNum * 11     // this gives: min 0 and max 10.99
let randomNumRoundToFloor = Math.floor(numBtnZeroAndTen)
// Shortened
let randNum = Math.floor(Math.random() * 10 + 1)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Which method is preferred for concatenating two strings?
A - Using “+”
B - Using ``

A

B - Back-ticks

console.log(The sum of ${a} and ${b} is ${a + b})

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

.length

A

length of string

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

.toUpperCase()

A

all capital letters

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

.toLowerCase()

A

all lower case letters

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

.substr(start, count)

A

start from starting index and return n characters.

DEPRECATED!!!

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

.substring(start, end)

.substring(start)

A

The substring() method returns the part of the string between the start and end indexes, or to the end of the string.

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

.split(by, count)

A

cuts out the string by substring and return n chunks

17
Q

What is the output of
let myName = “Iman Sayah”
console.log(myName.split(‘a’));

A

[ ‘Im’, ‘n S’, ‘y’, ‘h’ ]

18
Q

What is the output of
let myName = “Iman Sayah”
console.log(myName.split(‘a’, 2));

A

[ ‘Im’, ‘n S’ ]

19
Q

What is the output of
let myName = “Iman Sayah”
console.log(myName.split(‘’));

A

[
‘I’, ‘m’, ‘a’, ‘n’, ‘ ‘, ‘S’, ‘a’, ‘y’, ‘a’, ‘h’
]

20
Q

What is the output of
let myName = “Iman Sayah”
console.log(myName.split(‘ ‘));

A

[ ‘Iman’, ‘Sayah’ ]

21
Q

What is the output of
let myName = “Iman Sayah”
console.log(myName.split(‘X’));

A

[ ‘Iman Sayah’ ]

22
Q

.trim()

A

Removes the leading and trailing white space and line terminator characters from a string.

23
Q

.includes(substring)

A

checks if substring argument exists in the string

24
Q

.replace(substring, new)

A

replaces substring with new substring

25
Q

.charAt(index)

A

returns a new string consisting of the single UTF-16 code unit located at the specified offset into the string.

26
Q

What is the output of
“iman”.charAt(4)
?

A

””

27
Q

What is the output of
“iman”.charAt(3)
?

A

“n”

28
Q

What is the result of
“iman”.charCodeAt(3)
?

A

110

29
Q

What is the result of
“iman”.charCodeAt(5)
?

A

NaN

30
Q

.charCodeAt()

A

returns an integer between 0 and 65535 representing the UTF-16 code unit at the given index.

returns NaN when index is out of range.

31
Q

.indexOf()

A

returns the first index at which a given element can be found in the array, or -1 if it is not present.

32
Q

What is the result of

“iman sayah”.indexOf(“a”)

A

2

33
Q

What is the result of

“iman sayah”.indexOf(“t”)

A

-1