JS - Udemy Flashcards

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
Q

What are a few Math objects?

A
  • Math.round(4.9) = 5; .floor, .abs, .pow, .random
26
Q

What returns the data type?

A

typeof ___

27
Q

How to parse numbers from a larger string?

A
  • parseInt; - parseFloat;
28
Q

What’s the difference between == and ===?

A

` === checks for equality AND type

29
Q

IF, ELSE IF, ELSE: EX: Write a function - if x is > 10 return “>10”, else if x > 6 return that, else returns < 6

A
"if (x > 10) { 
   console.log('>10');
}
else if (x < 10 &amp;&amp; x > 6) {
   console.log('>6');
}
else {
console.log('<6')
}"
30
Q

What is ! Ex

A
  • Reverses truthiness; - !(3 < 4) = false
31
Q

What is the order of Logical Operators?

A

!, &&, then || (notwithstanding parentheses)

32
Q

EX: What conditional is best when you have one thing you’re checking against a set of values?

A
"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
Q

What’s another way of writing an IF/ELSE statement?

A

”- Ternary Operator; -

num = 6

num === 7 ? console.log(““lucky!””) : console.log(““BAD!””); = BAD!”

34
Q

JS array format?

A

let or const arrName = [0,1,2,3]

35
Q

What are the 4 basic Array Methods?

A
  • Push (add to end) , Pop (remove from end), Shift (remove from start), Unshift (add to start)
36
Q

How to join arrays?

A

old.concat(new)

37
Q

Arr method to search for a value?

A

arr.includes(‘string’)

38
Q

Arr method to reverse array?

A

arr.reverse()

39
Q

Arr method to combine elements?

A

arr.join(‘-‘)

40
Q

Arr method to copy portion of array?

A

arr.slice(start, end+1)

41
Q

Arr method to remove/replace elements?

A

arr.splice(startindex[deletecount[item1,item2,…

42
Q

Arr method to sort array?

A

arr.sort(compareFunction)

43
Q

What happens when you use const w/ arrays?

A

Elements can change, “Arr =” cannot be invoked

44
Q

What happens when you use const w/ arrays?

A

Elements can change, “Arr =” cannot be invoked

45
Q

EX: fitBitData obj

A
"const fitBitData = {
   totalSteps  : 588,
   totalMiles  :  2.3,
   avgSleep   :  '2:13'
};"
46
Q

How to access an Object Property?

A

obj[key] = value (key = number or ‘string’)

47
Q

EX: How to nest arr + obj in obj?

A
"const student = {
  name : 'Jon',
  strengths : ['Music','Art'],
  exams : {
    midterm : 92,
    final : 88
  }
};"
48
Q

EX: For Loop

A

“for(initial value[i]; condition; increment)

for(let i = 1; i <=10; i++){
  console.log('hello');
}"
49
Q

EX: How to loop over array? (Like each do | |?)

A
"for(let i = 0; i < array.length; i++) {
}"
50
Q

EX: While loop

A

“while(somethingIsTrue) {
action;
counter++;
}”

51
Q

EX: For..Of

A

”- Used for iterating through arrays

for (let ELEMENT of ARRAY) {
statement
}”

52
Q

For..In

A

”- Used for iterating through obj

for (let MOVIE in moviesObject) {
statement
}”

53
Q

JS ver. of Each_With_Index? ex.

A

“array.forEach(function (element, index) {

});”

54
Q

What to use instead of forEach when you want to stop looping upon solution? ex.

A

”- For loop with counter:

for (let i = 0; while i \_\_\_ condition; i +=1) {
}"
55
Q

How to create a hash table from arr? ex.

A
"let values = [4, 2, -1, 5, 6];
let hashTable = {};

values.forEach((value, index) => hashTable[value] = index);

hashTable[-1]; // 2
hashTable[6]; // 4

56
Q

What does the “break” keyword do in a loop?

A
  • Stops loop in a while loop; - diff from switch?