|
DataTypes
Data Types
In JavaScript, you can express integers in 3 different Bases:
Base 8 numbers can have digits only up to 7, so a decimal value of 18 would be an octal value of 22. Similarly, hexadecimal allows digits up to F, where A is equivalent to decimal 10 and F is 15. So, a decimal value of 18 would be 12 in hexadecimal notation. In order to distinguish between these three bases, JavaScript uses the following notation. Specifying bases in JavaScript
Floating point values can include a fractional component. A floating-point literal includes a decimal integer plus either a decimal point and a fraction expressed as another decimal number or an expression indicator and a type suffix
Floating point literals must, at a minimum, include a decimal integer and either the decimal point or the exponent indicator ("e" or "E"). As with integers, floating point values can be positive or negative.
Technically, a string literal contains zero or more characters enclosed, as you know, in single or double quotes:
NOTE: the empty string is distinct from the null value in JavaScript. NOTE: Strings are different from other data types in JavaScript. Strings are actually Objects. This will be covered later on.
A Boolean value is either true or false. Note: Unlike Java, C and other languages, in JavaScript Boolean values can only be represented with true and false. Values of 1 and 0 are not considered Boolean values in JavaScript.
The null value is a special value in JavaScript. The null value represents just that Nothing. If you try to reference a variable that isnt defined and therefore has no value, the value returned is the null value. Likewise, with the prompt() dialog box, if the user selects the Cancel button, a null is returned. (example) NOTE: This is distinct from a value of zero or an empty string where this is an "actual" value. The null value is indicated in JavaScript by the term null.
In addition to these values, some functions return a special value called NaN which means that the value is not a number, parseInt() and parseFloat() are an examples of functions that return NaN when the argument passed to them cannot be evaluated to a number. NOTE: Values can be tested to see if they are NaN by using the isNaN() function which returns true or false based on the nature of the argument passed to the function.
In order to make working with data types useful, you need ways to store values for later use. This is where variables come in. |