Core JavaScript

Data Types

Data in a JavaScript program can be of several different types. In the language, there are a few built-in types: number, boolean, string. Additionally, variables can have the value of a function or any of various kinds of an object. A variable that has never been set to a value is considered undefined.

DataTypes.html

<!DOCTYPE html>
<html>
<head>
    <title>XoaX.net's Javascript</title>
</head>
<body>
    <script type="text/javascript" src="DataTypes.js"></script>
</body>
</html>

DataTypes.js

// A number data type
document.writeln(typeof 3.14 + "<br />");
// A boolean data type
document.writeln(typeof true + "<br />");
// A string data type
document.writeln(typeof "XoaX.net" + "<br /><br />");

// An undefined variable
document.writeln(typeof Y + "<br /><br />");

// A function
var fnF = function(dX) { return 2.0*dX;}
document.writeln(typeof fnF + "<br /><br />");

// Different kinds of objects
// An array
var iaA = [2,3,6,9,2];
document.writeln(typeof iaA + "<br />");
// The null value
document.writeln(typeof null + "<br />");
// A programmer-defined and initialized object
document.writeln(typeof {dX:5.0, dY:3.0} + "<br />");


 

Output

 
 

© 2007–2024 XoaX.net LLC. All rights reserved.