Chapter 3. Data Types and Values
Computer programs work by manipulating values , such as the number 3.14 or the text “Hello World”. The types of values that can be represented and manipulated in a programming language are known as data types, and one of the most fundamental characteristics of a programming language is the set of data types it supports. JavaScript allows you to work with three primitive data types: numbers, strings of text (known as “strings”), and boolean truth values (known as “booleans”). JavaScript also defines two trivial data types, null and undefined, each of which defines only a single value.
In addition to these primitive data types, JavaScript supports a composite data type known as object. An object (that is, a member of the data type object) represents a collection of values (either primitive values, like numbers and strings, or composite values, like other objects). Objects in JavaScript have a dual nature: an object can represent an unordered collection of named values or an ordered collection of numbered values. In the latter case, the object is called an array . Although objects and arrays are fundamentally the same data type in JavaScript, they behave quite differently and will usually be considered distinct types throughout this book.
JavaScript defines another special kind of object, known as a function . A function is an object that has executable code associated with it. A function may be invoked to perform some kind of operation. ...
Get JavaScript: The Definitive Guide, Fourth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.