type conversions & math Flashcards
alert( “6” / “2” ); //returns?
3, strings are converted to numbers
let str = “123”;
alert(typeof str); // Returns
String
let str = “123”;
let num = Number(str);
alert(typeof num); // returns and why
number,
It becomes a number 123
let age = Number(“an arbitrary string instead of a number”);
alert(age); // returns?
NaN, conversion failed
Numeric conversion rules:
undefined becomes?
NAN
Numeric conversion rules:
Null becomes?
0
Numeric conversion rules:
true and false
1 & 0
Numeric conversion rules:
If the remaining string is empty, the result is _____
0
Numeric conversion rules:
String with characters// returns?
the number is “read” from the string. An error gives NaN.
alert( Number(“123z”) ); // returns?
NaN (error reading a number at “z”)
Numeric conversion rules:
Values that are intuitively “empty”, like 0, an empty string, null, undefined, and NaN, become _____.
false
False numeric conversion
0
empty string
null
undefined
NAN
alert( Boolean(“hello”) ); // return
true
alert( Boolean(“”) ); // returns
false
alert( Boolean(“0”) ); // returns
0
in JavaScript, a non-empty string is always true.