Data types
Posted by David on March 14th, 2007 filed in JavaScriptThere are two data types that JavaScript requires you to explicitly specify: the Array and Data data types.
JavaScript supports the following data types:
Array An ordered collection. For example:
var animals = new Array (”cat”, “dog”, “mouse”)
Boolean True/false data type (values of true or false only). For example:
var cookieDetected = false
var repeatVisitor = true
var repeatVisitor = true
Date Time and date data type. For example:
var today = new Date() // current time/date via system clock
var newYearsDay = new Date(2007,01,01) //specific date
var newYearsDay = new Date(2007,01,01) //specific date
null A special data type denoting nonexistence. For example:
if (emailAddress == null){ // check for null
alert(”please enter an e-mail address”)
}
alert(”please enter an e-mail address”)
}
Null is not the same as 0 (zero)
Number Numerical data type. For example:
var numberHits = 1234 //implied numeric data type
var numberHits = new Number(1234) //explicit
var numberHits = new Number(1234) //explicit
String String (text) data type. For example:
alert (”This is a string”) // implied string with double quotes
alert (’So is this’) // implied string with single quotes
var myString = new String(”Yet another string”) // explicit
alert (’So is this’) // implied string with single quotes
var myString = new String(”Yet another string”) // explicit