Projects Are About Humans. Deal With That!

JScript Data Types



There three main (primitive) data types in JScript: string, number and boolean. Like in any other language, strings are collection of characters (letters, digits, signs, blanks, etc.) strung together. The string type is used mainly to represent text, and the string values must be enclosed in matching pairs of single or double quotation marks.

When it comes to numbers, Jscript doesn't differentiate integers and floating point values, like other languages do. Integer values can be positive whole numbers, negative whole numbers, and 0. You can represent these numbers in base 10 (decimal), base 8 (octal), and base 16 (hexadecimal), but most numbers in JScript are written in decimal. If you want to specify an octal integer, you should add a leading zero in front of the number containing digits from 0 to 7. If you add 8 or 9, the number will be interpreted as a decimal number. To represent hexadecimal integers, you must add the characters "0x" in front of the number. Hexadecimal numbers can contain digits from 0 through 9, and letters A through F.

Floating-point values are whole numbers with a decimal portion. You can also express these values using a scientific notation: the character "e" is used to represent "ten to the power of". You should know that numbers beginning with "0x" and "00″ who also contain a decimal point will generate an error, because floating-point values are available only for decimal values, and not also octal or hexadecimal values.

While a number and a string can contain lots of values, the boolean data type can only contain two: true or false. This is because a Boolean value is a truth-value, and it expresses whether an expression evaluates to true of false.

There are two special data types in JScript: "null" and "undefined". The null data type can only hold one value: null; this data type cannot be used as the name of a function or a variable. Data containing null is interpreted as containing "no value" or "no object". This means that is doesn't hold a valid number, string, boolean, array or object; so if you want to erase the contents of a variable, without deleting it, you can always assign it the null value.

The undefined data type is used instead of display some error messages, for example when some data has been declared, but no value was assigned to it.

No comments yet. Be the first.

Leave a reply