Variables, Types, and Collections Flashcards

1
Q

8 data types

A

string, bigint, symbol, object, null, and undefined

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

let and const

A

block scoped

block = anything inside curly braces

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

when we don’t assign a value to a variable

A

undefined

except with const (you will get SyntaxError: missing initializer in const declaration)

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

check typeof

A

if (typeof role == ‘undefined’)

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

which three data types have wrapper functions?

A

Boolean, Number, String

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

which two datatypes represent absence of data?

A

null, undefined

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

typecasting methods

A

Number()
String()
Boolean()
toString() - used to covered a number to a string
parseInt() - parse a string argument to an integer or NaN
parseFloat() - method used to parse an argument to floating point

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

array construction

A
var brands = ["Fender", "VOX", "Line6"]
var brands = new Array("Fender", "VOX", "Line6")
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Number type in JS

A

represents any number between -(2^53 - 1) and (2^53 - 1)

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

most common string methods

A

toLowerCase()
toUpperCase()

concat(str [,…str]) - combines two or more strings and returns a new string
includes(searchString, [,position])
indexOf(searchValue [, fromIndex]) = returns the index of a value or -1 if not found
replace(searchFor, replaceWith)
substring(indexStart [, indexEnd]) - the substring() method returns a part of the string between the start and end indexes or the start index to the end of the string
search()
padStart() & padEnd()
trim()

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

common methods for Number object

A

isNaN() - static method can be used to determine whether a value is NaN

isInteger()

parseFloat(str) & parseInt(str [,radix])

toFixed(digits) - returns number that has the specified number of digits after the decimal point

toString([radix])

valueOf() - returns primitive value of specified number object

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

common date methods

A
now() = returns current time in milliseconds
parse() = parses a date string and returns milliseconds
UTC() = returns milliseconds in UTC
Get Methods (getDay, getMonth, getHours, etc)
Set Methods (setFullYear, setMinutes, setSeconds, etc)
UTC Methods (getUTCDate, setUTCdate)

toString() - returns a string value of a date object
toDateString() - returns the date value of the date object without the time in a string format
toUTCString() - converts a date to a string using the UTC time zone
toISOString() - convert UTC time into a simplified ISO-8601 format
toLocaleDateString() - return a date value or parts of date in a specified locale
getDate / setDate

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

type coercion with different operators

A

== or !=
coerces primitives to numbers except for null and undefined

comparison operators
coerces primitives to numbers

logical operators
coerce primitives to boolean

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

type coercion with other primitives

A

symbol: evaluated as true in boolean coercion / cannot be implicitly coerced to a string or number
null: evaluated as false / 0 / null (string coercion)
undefined: false / NaN in numeric / undefined in string

NaN: false / NaN in string coercion

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

falsy values

A
false
0
-0
0n (BigInt 0)
''
null
undefined
NaN
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

double bang

A

coerces to the equivalent boolean value

17
Q

for in loop
vs.
for of loop

A

for in loop - when concerned with index

for of loop - for simplicity when you are just trying to access the values

18
Q

adding elements to arrays

A

push() - add one or more element to the end of an array; returns the new length of the array

unshift() - add one or more elements to the beginning of array; returns new length

splice() - allows modifying the contents of an array; used to add elements starting from a specific condition

19
Q

removing array elements

A

pop() - can be used to remove the last element from an array, returns removed element

shift() - remove first element; returns removed element

splice() - used to remove or replace, returns an array containing the removed elements

20
Q

SLICE()

A

used to make a copy of an array or a portion of an array; does not change original array

21
Q

finding array elements

A

includes()
indexOf()
lastIndexOf() - returns the last index of the given element in an array
findIndex() - returns first index that satisfies the given condition
find() - returns the value of the first element that satisfies the condition; undefined otherwise

22
Q

advanced data manipulation

A

map() - creates a new array based on a callback function that is invoked for every element of the original array

filter() - create a new array that contains elements which pass the given condition in a callback function

reduce() - uses the specified reducer function to return a single output value based on the reduction

flat() - used to create a new array containing all the sub-array elements concatenated into the original array recursively up to the specified path

every() - used to check whether all the elements of an array pass the given condition

some() - used to check if at least one element of an array passes the given condition in a callback function

23
Q

spread / rest operator

A

spreads the elements of array instead of the array itself

24
Q

in json…properties and any strings….

A

are enclosed within double quotes

25
Q

how do we convert a js object to json

A

stringify

SERIALIZED

26
Q

how to access JSON object like a JS object

A

parse()

DESERIALIZE

27
Q

how to iterate over data received

A

for in loop to iterative over properties

or object.entries (gets an array of key:value pairs)

28
Q

functions can be…

A

assigned to a variable
stored in an array
passed and returned
property of an object (method)

29
Q

6 types of functions

A
named functions
anonymous function
recursive function
outer function
inner function
immediately invoked (IIFE)
30
Q

IIFE

A

put parenthesis immediately after defining it

31
Q

arrow function considerations

A

this is treated differently

traditional functions: the this keyword is set to the object that invoked the function; otherwise, the this keyword defaults to the global variable

arrow functions: does not default to the global object; the value of this is determined by the context of where the function is called

32
Q

closure

A

allows code to access parent scope even after code is finished

33
Q

apply, call, bind

A

apply() - invokes a function and assigns the object passed in to the keyword ‘this’. arguments for the function are passed in as an array.

call() - invokes a function and assigns the object passed in to “this”. arguments are passed in as a comma separated list.

bind() - returns a new function; the object passed in is this when the function is invoked; arguments may be bound to the function as well

34
Q

object class methods

A

assign() - used to copy all the enumerable own properties from one or more source objects to a target object

entries() - can be used to get an array of all the key-value pairs of an object’s own enumerable string properties

values() - get array of all obj’s values

defineProperties() - define new or modify existing (also, defineProperty for just one)

freeze() - changes can no longer be made

preventExtensions() - prevents the addition of new properties

seal() - prevents new properties and deletions

is() - used to determine whether two values are the same

35
Q

object instance methods

A

hasOwnPropertyOf()
isPrototypeOf()
toString()
valueOf()