JS - Udemy Flashcards

(56 cards)

1
Q

ES6 def & features

A

Var, arrow functions?

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

How to get to & run code in console?

A
  • Control+Shift+C or Inspect or More Tools; -
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is modulo? + ex

A
  • %, returns remainder; - 25 % 5 = 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to notate exponents?

A

5**2 returns 25

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

What is the order of operations?

A

PEMDAS - parentheses, exponents, mult, div, add, sub

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

What is NaN & what will return it?

A

0/0; NaN + a number;

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

How does the browser read JS?

A
  • HTML file, include
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Quick way to view .js in browser?

A
  • Open html file in file explorer that contains .js tag
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What’s an Unary Operator? Ex.

A
  • ++ (existingVar+=1); – (existingVar-=1);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the primitive types?:

A
  • Number, String, Boolean, Null, Undefined
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Booleans

A
  • true & false; - 1 or 0
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What does null mean?

A
  • Absence of any value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does Undefined mean?

A
  • Variable with no assigned value
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

List the falsey values

A

false, 0, “”, null, undefined, NaN

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

How to get the index (content) of a string/letter? ex.

A

string[1] = t

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

How to convert a string to upper? ex

A

string.toUpperCase( )

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

How to convert a string to lower? ex

A

string.toLowerCase( )

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

What does Trim do? ex.

A

” string “.trim = “string”

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

How to get the index (letter) of a string? ex

A

string.indexOf(“tr”) = 1

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

How to return a fragment of a string? ex

A

string.slice(0,2) = “str”

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

How to substitute part of a string? ex

A

string.replace(‘g’, ‘z’) = “strinz”

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

How to keep a quote or backslash in a string from fucking up your day? ex

A
  • Escape Characters; - / preceding a “ or ‘ or /
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How to insert expressions, variables etc. into a string? ex

A
  • Template Literals –NOT QUOTES! TILDE; - String ${3+4} ${var}
24
Q

What is the Math object? ex

A
  • Math. contains methods
25
What are a few Math objects?
- Math.round(4.9) = 5; .floor, .abs, .pow, .random
26
What returns the data type?
typeof ___
27
How to parse numbers from a larger string?
- parseInt; - parseFloat;
28
What's the difference between == and ===?
` === checks for equality AND type
29
IF, ELSE IF, ELSE: EX: Write a function - if x is > 10 return ">10", else if x > 6 return that, else returns < 6
``` "if (x > 10) { console.log('>10'); } else if (x < 10 && x > 6) { console.log('>6'); } else { console.log('<6') }" ```
30
What is ! Ex
- Reverses truthiness; - !(3 < 4) = false
31
What is the order of Logical Operators?
!, &&, then || (notwithstanding parentheses)
32
EX: What conditional is best when you have one thing you're checking against a set of values?
``` "switch (day) { case 1: return ""Monday""; break; case 2: return ""Tue""; default: return ""else value here""; } ``` use break for each case you don't want to stop - default is ""else"""
33
What's another way of writing an IF/ELSE statement?
"- Ternary Operator; - num = 6 num === 7 ? console.log(""lucky!"") : console.log(""BAD!""); = BAD!"
34
JS array format?
let or const arrName = [0,1,2,3]
35
What are the 4 basic Array Methods?
- Push (add to end) , Pop (remove from end), Shift (remove from start), Unshift (add to start)
36
How to join arrays?
old.concat(new)
37
Arr method to search for a value?
arr.includes('string')
38
Arr method to reverse array?
arr.reverse()
39
Arr method to combine elements?
arr.join('-')
40
Arr method to copy portion of array?
arr.slice(start, end+1)
41
Arr method to remove/replace elements?
arr.splice(startindex[deletecount[item1,item2,...
42
Arr method to sort array?
arr.sort(compareFunction)
43
What happens when you use const w/ arrays?
Elements can change, "Arr =" cannot be invoked
44
What happens when you use const w/ arrays?
Elements can change, "Arr =" cannot be invoked
45
EX: fitBitData obj
``` "const fitBitData = { totalSteps : 588, totalMiles : 2.3, avgSleep : '2:13' };" ```
46
How to access an Object Property?
obj[key] = value (key = number or 'string')
47
EX: How to nest arr + obj in obj?
``` "const student = { name : 'Jon', strengths : ['Music','Art'], exams : { midterm : 92, final : 88 } };" ```
48
EX: For Loop
"for(initial value[i]; condition; increment) ``` for(let i = 1; i <=10; i++){ console.log('hello'); }" ```
49
EX: How to loop over array? (Like each do | |?)
``` "for(let i = 0; i < array.length; i++) { }" ```
50
EX: While loop
"while(somethingIsTrue) { action; counter++; }"
51
EX: For..Of
"- Used for iterating through arrays for (let ELEMENT of ARRAY) { statement }"
52
For..In
"- Used for iterating through obj for (let MOVIE in moviesObject) { statement }"
53
JS ver. of Each_With_Index? ex.
"array.forEach(function (element, index) { });"
54
What to use instead of forEach when you want to stop looping upon solution? ex.
"- For loop with counter: ``` for (let i = 0; while i ___ condition; i +=1) { }" ```
55
How to create a hash table from arr? ex.
``` "let values = [4, 2, -1, 5, 6]; let hashTable = {}; ``` values.forEach((value, index) => hashTable[value] = index); hashTable[-1]; // 2 hashTable[6]; // 4 "
56
What does the "break" keyword do in a loop?
- Stops loop in a while loop; - diff from switch?