Page 141 - DCAP408_WEB_PROGRAMMING
P. 141
Unit 5: Scripting Language
Notes
Did u know? What is the basic use of data type?
Undeclared variables and variables declared without a data type are assigned the Object
data type. This makes it easy to write programs quickly, but it can cause them to execute
more slowly.
5.2.1 Primitive Data Types
Primitive data types are the simplest building blocks of a program. They are types that can be
assigned a single literal value such as the number 5.7, or a string of characters such as “hello”.
JavaScript supports three core or basic data types:
numeric
string
Boolean
In addition to the three core data types, there are two other special types that consist of a single
value:
null
undefined
Numeric Literals
JavaScript supports both integers and floating-point numbers. Integers are whole numbers
and do not contain a decimal point; e.g., 123 and –6. Integers can be expressed in decimal
(base 10), octal (base 8), and hexadecimal (base 16), and are either positive or negative
values.
Floating-point numbers are fractional numbers such as 123.56 or –2.5. They must contain
a decimal point or an exponent specifier, such as 1.3e–2. The letter “e” for exponent notation
can be either uppercase or lowercase.
JavaScript numbers can be very large (e.g., 10308 or 10–308 ).
Table 5.1
12345 Integer
23.45 float
.234E–2 scientific notation
.234e+3 scientific notation
0x456fff hexadecimal
0x456FFF hexadecimal
0777 Octal
String Literals and Quoting
String literals are rows of characters enclosed in either double or single quotes. The quotes
must be matched. If the string starts with a single quote, it must end with a matching
single quote, and likewise if it starts with a double quote, it must end with a double quote.
Single quotes can hide double quotes, and double quotes can hide single quotes:
LOVELY PROFESSIONAL UNIVERSITY 135