Language Basics Flashcards
(82 cards)
What does the function isFinite() do?
This function returns true if a value is finite (that is, it occurs between the minimum and maximum)
How can you get the largest and smallest number available?
Number.MAX_VALUE
Number.MIN_VALUE
What is wrong with this comparison?
a + b == 0.3
You should expect small rounding issues in JavaScript.
0.1 + 0.2 does not equal 0.3
How should you define a variable that is later meant to hold an object?
It is advisable to initialize the variable to null.
var car = null;
This allows you to explicitly check for the value null to determine of the variable has been filled with an object reference at a later time.
if (car != null) { // do something with car }
What is the special numeric value NaN used to indicate?
When an operation intended to return a number has failed.
What is unique about NaN
- Any operation involving NaN always returns NaN
2. NaN is not equal to any value, including NaN
How do you determine if a value is NaN?
isNaN() takes a single value, attempts to convert it into a number and returns true or false.
What does Number(“ “); return?
0 - empty strings return zero.
What does parseInt(“ “); return?
NaN, empty strings return NaN. Leading white space is ignored until the first non white space character is found. If that character isn’t a plus, minus, or number NaN is returned.
What does parseInt(“1234blue”) return?
1234, after parseInt() finds the first character and it’s a number, plus, or minus, the conversion then goes on to the second character and continues on until either it reaches the end of the string or a non numeric character.
What does radix mean.
Number of digits.
What is the second argument in parseInt() used for?
parseInt(“10”, 10);
parseInt() provides a second argument - the radix (base) to use.
Most of the time you’ll be parsing decimal numbers, so it’s good to include 10 as the second argument.
What’s the difference between parseFloat() and parseInt()?
In parseFloat() a decimal point is a valid character the first time it appears.
Also, in parseFloat() initial zeros are always ignored. And there is no radix mode - so all hex numbers become 0.
does toString() take any arguments?
In most cases, no. But, when used on a number value, toString() accepts a single argument: the radix in which to output the number.
var num = 10; num.toString(2); // output 10 in binary
What are unary operators?
Operators that work on only one value.
How do you increment a variable in short hand?
var age = 29; \++age;
The variable’s value is changed before the statement is evaluated.
How do you decrement a variable in short hand?
var age = 29; --age;
The variable’s value is changed before the statement is evaluated.
What is the difference between age++ and ++age?
When using postfix increment (age++), the increment doesn’t occur until after the containing statement has been evaluated.
What’s the value of num3?
var num1 = 2; var num2 = 20; var num3 = num1-- + num2
22
What’s the value of num3?
var num1 = 2; var num2 = 20; var num3 = --num1 + num2
21
What does this return?
+“01”
1
What does this return?
+false
0
What does this return?
+true
1
Negative numbers are stored in binary code in a format called what?
two’s complement