IES: JS-deck 13 Flashcards

1
Q

JS isNaN ( )

A
  • “Not a Number”
  • JS built-in function
  • Similar to parseFloat() and parseInt(), isNaN() first attempts to find a number at the beginning of the specified value
  • Boolean: This function returns true if it cannot find a number at the beginning, and returns false if it does.
    Ex.
    ~~~
    let sum, net = ‘25’, tax = 5.00
    isNaN(net) ```
    (before the ‘$’ prefix is added),
    return = “false
    isNaN(net)
    (after the ‘$’ prefix is added),
    return = “true
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

JS Coercion

A
  • Conversion of data types
  • can be explicit or implicit
  • Implicit coercion:
    Ex. '42' + 8 = 428
  • Explicit coercion:
    Ex. String(42)
    return = ‘42’
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

JS String ()

A
  • method
  • Can return a string representation, in the string data type, of a number specified within its parantheses
    Ex. String (42)
    return = the number ‘42’ as a string data type
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

JS toString()

A
  • method
  • you can append a call onto a variable name to return a string representation of a stored data type.
    Ex.
    (variable named “num” is assigned a number)
    num.toString()
    return = (a string version of that stored / assigned number)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

JS Operator “ + “

A
  • Operation
    1. Addition of numbers
    2. Concatenation of strings
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

JS Operator “ - “

A
  • Operation: Subtraction
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

JS Operator “ / “

A
  • Operation: Division
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

JS Operator “ % “

A
  • Operation: Modulus
  • returns the remainder of a division operation
  • Divides the first operand by the second operand and returns the remainder
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

JS Operator “ ++ “

A
  • Operation: Increment
  • Increases the operand value by 1 and returns the new value
  • most commonly used to count iterations of a loop
  • used in two different ways to subtly different effects
    1. when prefixing the operand, value is immediately changed before the expression is evaluated
    2. when post-fixing the operand, the expression is evaluated first then the value gets changed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

JS Operator “ – “

A
  • Operation: Decrement
  • Decreases the operand value by 1 and returns the new value
  • most commonly used to count iterations of a loop
  • used in two different ways to subtly different effects
    1. when prefixing the operand, value is immediately changed before the expression is evaluated
    2. when post-fixing the operand, the expression is evaluated first then the value gets changed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

JS Operator “ ** “

A
  • Operation: Exponentiation
  • Operator returns the result of a first operand raised to the power of a second operand
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

JS Using modulus operator to determine a number’s parity

A
  • Ex.
let parity = (numOne % 2 !==0) ? 'Odd' : 'Even'
console.log(numOne + 'is' + parity) 
 
parity = (numTwo % 2 !==0) ? 'Odd' : 'Even'
console.log(numTwo + 'is' + parity)
  • HERE’S HOW IT WORKS:
    1. number % 2: This calculates the remainder when number is divided by 2.
    2. ?: This is the ternary operator. It checks if the result of number % 2 is truthy or falsy.
    3. If the remainder is 1 (or any non-zero value, which is truthy), it means the number is odd, and the expression after the ? is returned, which is ‘Odd’.
    4. If the remainder is 0 (which is falsy), it means the number is even, and the expression after the : is returned, which is ‘Even’.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

JS Operator “ ! “

A
  • Logical NOT :
  • This operator converts the operand to a boolean value and then inverts it.
  • If the operand is truthy (a value that evaluates to true in a boolean context), ! makes it false. If it’s falsy (evaluates to false), ! makes it true.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

JS Operator “ == “

A
  • The loose equality operator
    Ex.
    ==0
    checks if the value is loosely equal to zero
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

JS “Operands”

A
  • Values specified in Operation Statements
    Ex.
    5+2
    “5” & “2” are the operands
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

JS Operator “ = “

A
  • assignment operator
  • Operators inclusive of “=” our shorthand forms of longer expression (excepting the simple “=” assignment operator)
  • MEANS “assign,” NOT “equals” (to avoid confusion with the JS “===” equality operator)
  • Example a=b
  • Equivalent a=b (a gets assigned the value contained in variable b : becomes a’s new stored value)
17
Q

JS Operator “ += “

A
  • Performs the arithmetical operation on the two operands first
  • Then assigns the results of that operation to the first variable - so that becomes its new stored value.
  • Example: a+=b
  • Equivalent: a=(a+b)
18
Q

JS Operator “ -= “

A
  • Performs the arithmetical operation on the two operands first
  • Then assigns the results of that operation to the first variable - so that becomes its new stored value.
  • Example: a-=b
  • Equivalent: a=(a-b)
19
Q

JS Operator “ *= “

A
  • Performs the arithmetical operation on the two operands first
  • Then assigns the results of that operation to the first variable - so that becomes its new stored value.
  • Example: a*=b
  • Equivalent: a=(a*b)
20
Q

JS Operator “ /= “

A
  • Performs the arithmetical operation on the two operands first
  • Then assigns the results of that operation to the first variable - so that becomes its new stored value.
  • Example: a/=b
  • Equivalent: a=(a/b)