Lesson 1: Introducing JavaScript CHAPTER 3 67
adds the JavaScript Console, which can simplify debugging. Search the web for other tools
such as Resharper by JetBrains. This tool has many features that can help you with writing
JavaScript code.
Understanding the role of data
When you want to create a program, you typically find that the program must access and
manipulate data because data is at the root of all systems. You collect data, manipulate data,
store data, retrieve data, display data, and so on.
The data will be in different forms, but most data can be broken into smaller pieces called
values. JavaScript defines a value type as an object, a primitive value, or a function. A primitive
value is a datum that is represented at its lowest level of the language implementation and, in
JavaScript, is one of the following types: undefined, null, Boolean, number, or string. A func-
tion is a callable object, and a function that is a member of an object is called a method.
JavaScript also defines the following built-in objects: the global object, the Object object,
the Function object, the Array object, the String object, the Boolean object, the Number
object, the Math object, the Date object, the RegExp object, the JSON object, and several
variations of Error objects.
Using expressions to produce data
An expression is a piece of code that produces a value. An expression can be a simple value,
or it can contain operands and operators. Mathematical symbols, such as the plus, minus,
divide, and multiply signs, are examples of operators. Numbers are operands. The operators
cause an operation to be executed by using the operands on each side of the operator. Note
that an operand can be a value, or it can be another expression.
Understanding the number type
Numbers are one of the primitive types defined in JavaScript. A numeric value is a member of
the number type and corresponds to a double-precision, 64-bit binary format, IEEE 754 value.
In JavaScript, all numeric values are internally represented as floating point values. The 64-bit
number is divided into three components: the fraction is 52 bits (bits 0 to 51), the exponent is
11 bits (bits 52 to 62), and the sign is a single bit (bit 63).
The highest integer number that can be represented internally is 2^53 , which is
9,007,199,254,740,994. After that, numbers are stored as a fraction times 2exponent. When per-
forming integer calculations, the results are always precise, but when working with fractions,
problems can arise. A calculation such as 0.1 + 0.2 will not result in 0.3 due to the manner
in which fractions are stored. The result will be 0.30000000000000004 because 0.1 and 0.2
cannot easily be stored as a binary fraction value. For situations like this, you might need to
round your results to truncate the fraction to a fixed number of decimal places.
Key
Te rms
Key
Te rms