Editing JavaScript/Notes/TypeConversion
Jump to navigation
Jump to search
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
== Types == | == Types == | ||
• Number | |||
• String | |||
• Boolean | |||
• Null | |||
• Undefined | |||
• Object | |||
There are five primitive types in JavaScript. Everything else is an object. | There are five primitive types in JavaScript. Everything else is an object. | ||
Line 22: | Line 22: | ||
var t = !""; // true. Empty string is falsy. | var t = !""; // true. Empty string is falsy. | ||
var f = !"f"; // false. Non-empty strings | var f = !"f"; // false. Non-empty strings are not falsy. | ||
Boolean(""); // false. | Boolean(""); // false. | ||
</source> | </source> | ||
Line 98: | Line 98: | ||
=== Converting to Number === | === Converting to Number === | ||
Converting strings is a very common requirement and many approaches can be used. Any mathematical operator except the concatenation/addition operator will force type-conversion to number. | Converting strings is a very common requirement and many approaches can be used. Any mathematical operator except the concatenation/addition operator will force type-conversion to number. | ||
== parseInt(s, radix) == | == parseInt(s, radix) == |