JavaScript

Core JavaScript Language Features

The core JavaScript Language features comprise values, variables, literals, expressions, operators (including assignment, comparison, arithmetic, bitwise, logical, string, and special operators), regular expressions (patterns used to match character combinations in strings), statements, functions (procedures that your application can perform), objects (named containers for values), properties, and methods. You can create your own objects.

Values, or data types

Note that JavaScript is case sensitive, so null is not the same as Null or NULL, etc. Note that there is no explicit distinction between integer and real-valued numbers. Note that there is no explicit date data type, though you can use the Date object and its methods to handle dates.

Data Type Conversion

You do not have to specify the data type of a variable when you declare it, as JavaScript is a dynamically typed language. JavaScript will automatically do any type conversion necessary as you go along. You can change the type of a variable you assign if you want. For instance, you could assign: var target = 65 then, without error, later assign a string value such as: var target = "date I retire"

If you use the + operator with a numeric and a string value, the numeric value is always converted to a string. With other operators it is not. So:


x =  "My age is 2" + 1				// sets x to "My age is 21"
document.writeln("The value of x is " + x);	// returns "My age is 21"
document.writeln("2" + 1);			// returns 21
document.writeln("2" - 1);			// returns 1

Back to top     Home     Serious Stuff

© 2001. Copyright Sue Nethercott.