Core JavaScript contains a pre-defined core set of objects and a core set of language elements. The tutorials provide details of each component, but basically, here are the major components and what they do:
Like most modern programming languages, JavaScript is an object-oriented system, meaning it uses the concept of objects to identify and handle information. Much like objects in the real world, we can use them to gather, store, access, and modify information, and we can use them to do something.
JavaScript objects fall into either of two categories: intrinsic objects, which are objects built-in to the language itself; and user-defined objects, which are objects that can be defined for particular use in a script.
The core JavaScript objects as defined in the ECMA standard are listed in the Objects Summary.
In addition, the W3C DOM specification defines a specific set of generic objects, such as the window, document, and navigator objects, and exposes all HTML elements as objects that are accessible to ECMA-standard scripts. These are described in the HTML Elements/Dynamic HTML Objects reference.
Objects are, essentially, collections of properties and methods.
A property is basically a value or set of values that is part of or associated with an object. Properties typically contain information describing an object. Some objects' properties are fixed and can only be retrieved, while most may be set and modified. The basic notation for accessing an object's property is:
object.property
The Properties Summary describes the ECMA standard core set of properties.
In addition, the Dynamic HTML Attributes reference lists all the available properties that apply to the generic objects as defined in the DOM, which may be used with the ECMA-standard language.
Moreover, all HTML attributes are accessible as object properties via ECMA standard scripts.
A method is basically a function that is part of or associated with an object. Methods are a kind of object behavior that typically performs some built-in object action. The basic notation for accessing an object's method is:
object.method ( )
The Methods Summary describes the built-in methods that apply to the ECMA-standard core set of objects.
In addition, the reference on Dynamic HTML Methods lists all the available methods that apply to the generic objects as defined in the DOM, which may be used with the ECMA-standard language.
Control structures are special forms of statements that allow us to control a program's flow. Scripts can be made to do things such as make decisions or automate repetitive processes, through the use of conditional, object manipulation, exception handling, and loop statements.
The core set of statements as defined in the ECMA-standard are described in the Statements Summary.
Like mathematical expressions, JavaScript uses symbols such as + and =, called operators, to indicate what actions or operations are to be performed on JavaScript expressions.
Operators in JavaScript fall into six general categories:
- assignment ( for assigning values to variables )
- computational ( for addition, subtraction, etc. )
- logical ( for comparisons )
- string ( for combining characters )
- bitwise ( for binary representation of data )
- special operators ( for special functions )
The Operators Summary provides a description of all the operators as defined in the ECMA standard.
A variable is a named unit of data storage that we define, whose value we can initially assign and later retrieve and modify as needed, using it’s name; you can think of variables as notes on a scratchpad, where we keep bits of data in memory for later use. Basic notation is:
name = value
Unlike most programming languages, JavaScript does not have explicit types of data; the data type is defined by the value that is assigned to the variable, which can be any of the following: strings, numbers, objects, Booleans, null and undefined.
Keywords are basically the words internally used by the language and must be reserved for its own use, meaning they should not be used for naming our own identifiers or values. Other words that are wise to avoid are any that are already the names of intrinsic JavaScript objects, properties, methods, and functions.
The Language Reference includes an alphabetic list of all ECMA-standard keywords.
Functions are the fundamental building blocks in JavaScript. The real power of JavaScript lies in allowing users to define their own sets of functions, using all of the language elements described above.
A function is basically a reusable set of statements, that can be called to perform an action, such as to retrieve, to set, to compute or validate data. Functions may be given values to process ( called parameters ), and may return values to the calling object.
In the following sections, we take a closer look at each of these core components, and how we can make use of them.
Some relevant references: