The Language Flashcards
What is this scientific notation equal to?
2.998e8
2.998 x 10^8 = 299,800,000
What result do you get when you try to calculate any number of other numeric operations that don’t yield a precise, meaningful result.
NaN.
What are the characters you get when you press enter?
Newlines
How do you escape a character?
\
How do you create a newline?
\n
How do you create a tab character?
\t
What does the typeof operator do?
Typeof produces a string value naming the type of the value you give it.
Can strings be compared using booleans?
Yes. Ex: console.log(“Aardvark”
Are uppercase letters “less than” or “more than” lowercase letters?
uppercase letters are always “less” than lowercase ones, so “Z”
What value in Javascript is not equal to itself?
NaN. console.log(NaN == NaN) // -> false
NaN is supposed to denote the result of a nonsensical computation, and as such, it isn’t equal to the result of any other nonsensical computations.
When is the logical “and” operator true?
console.log(true && false) // → false console.log(true && true) // → true
It is a binary operator, and its result is true only if both the values given to it are true.
When is the logical “or” operator true?
It produces true if either of the values given to it is true.
console.log(false || true) // → true console.log(false || false) // → false
What kind of operator is the “not” operator and what does it do?
Not is written as an exclamation mark (!). It is a unary operator that flips the value given to it—!true produces false and !false gives true.
How does precedence work with standard boolean operators?
|| has the lowest precedence, then comes &&, then the comparison operators (>, ==, and so on), and then the rest.
What is the “conditional” operator also called and how does it work?
Sometimes just called the “ternary” operator since it is the only such operator in the language). The value on the left of the question mark “picks” which of the other two values will come out. When it is true, the middle value is chosen, and when it is false, the value on the right comes out.
console.log(true ? 1 : 2); // → 1 console.log(false ? 1 : 2); // → 2
What do the following expressions result in?
console. log(8 * null)
console. log(“5” - 1)
console. log(“5” + 1)
console. log(“five” * 2)
console. log(false == 0)
console.log(8 * null) // → 0 console.log("5" - 1) // → 4 console.log("5" + 1) // → 51 console.log("five" * 2) // → NaN console.log(false == 0) // → true
Define what “coercion” is. What’s another term for it?
Automatic type conversion. When an operator is applied to the “wrong” type of value, JavaScript will quietly convert that value to the type it wants, using a set of rules that often aren’t what you want or expect. This is called type coercion.
When is the last behavior below useful?
console.log(null == undefined); // → true console.log(null == 0); // → false
That last piece of behavior is often useful. When you want to test whether a value has a real value instead of null or undefined, you can simply compare it to null with the == (or !=) operator.
When converting strings and numbers to Boolean values, what 3 values count as false?
The rules for converting strings and numbers to Boolean values state that 0, NaN, and the empty string (“”) count as false, while all the other values count as true.
What is “short-circuit evaluation”?
In the case of true || X, no matter what X is—even if it’s an expression that does something terrible—the result will be true, and X is never evaluated. The same goes for false && X, which is false and will ignore X.
Define an “expression”
A fragment of code that produces a value is called an expression. Every value that is written literally (such as 22 or “psychoanalysis”) is an expression. An expression between parentheses is also an expression, as is a binary operator applied to two expressions or a unary operator applied to one.
What is the simplest kind of statement?
The simplest kind of statement is an expression with a semicolon after it. This is a program:
1;
!false;
When the = operator is used on existing variables, what does it do to the variable?
When a variable points at a value, that does not mean it is tied to that value forever. The = operator can be used at any time on existing variables to disconnect them from their current value and have them point to a new one.
var mood = "light"; console.log(mood); // → light mood = "dark"; console.log(mood); // → dark
What are other words used to mean that you are executing a function?
Executing a function is called invoking, calling, or applying it.