JavaScript definite guide – Arrays

An array is an ordered collection of values. Each value is called an element, and each element has a numeric position in the array, known as its index.

  • JavaScript arrays are untyped: an array element may be of any type, and different elements of the same array may be of different types. Array elements may even by objects o other arrays, which allows you to create complex data structures, such as arrays of objects and arrays of arrays.
  • JavaScript arrays are zero-based and use 32-bit indexes: the index of the first element is 0, and the highest possible index is 4294967294 (2^32−2 ), for a maximum as needed and there is no need to declare a fixed size for the array when you create it or to reallocate it when the size changes.
  • JavaScript arrays may be sparse: the elements need not have contiguous indexes and there may be gaps.
  • Every JavaScript array has a length property.
    • For non sparse arrays, this property specifies the number of elements in the array.
    • For sparse arrays, length is larger than the index of all elements.

JavaScript arrays are specialized form of JavaScript object, and array indexes are really little more than property names that happen to be integers. Implementations typically optimize arrays so that access to numerically indexed array elements is generally significantly faster than access to regular object properties.


Inner link

JavaScript definite guide – Objects

JavaScript's fundamental datatype is the object. An object is a composite value: it aggregates multiple values (primitive values or other objects) and allows you to store and retrieve those values by name. An object is an unordered collection of properties, each of which has a name and a value.

Any value in JavaScript that is not a string, a number, true, false, null or undefined is an object. And even though strings, numbers, and booleans. Are not objects, they behave like immutable objects.

A property has a name and a value. A property name may be any string, including the empty string, but no object may have two properties with the same name. The value may be any JavaScript value, or it may be a getter or a setter function (or both). In addition to tis name and value, each property has associated values that we'll call property attributes:

  • The writable attribute specifics whether the value of the property can be set.
  • The enumerable attribute specifies whether the property name is returned by a for/in loop.
  • The configurable attribute specifies whether the property can be deleted and whether its attributes can be altered.

Prior to ECMAScript 5, all properties in objects created by your code are writable, enumerable, and configurable. In ECMAScript 5, you can configure the attributes of your properties. 6.7 explains how to do this:

Read More »

JavaScript definite guide – Functions

In JavaScript, functions are objects, and they can be manipulated by programs. Javascript can assign functions to variables and pass them to other functions, for example. Since functions are objects, you can set properties on them, and even invoke methods on them.

JavaScript function definitions can be nested within other functions, and they have access to any variables that are in scope where they are defined. This means that JavaScrip functions are closures, and it enables important and powerful programming techniques.

Defining Functions

Functions are defined with the function keyword, which can be used in. A function definition expression, or in a function declaration statement. In either form, function definitions begin with the keyword function followed by these components:

  • An identifier that names the function. The name is a required part of function declaration statements:
  • A pair of parentheses around a comma-separated list of zero or more identifiers.
  • A pair of curly braces with zero or more Javascript statements inside. These statements are the body of the function: they are executed whenever the function is invoked.

Notice that a function defined as an expression is only useful if it is part of a larger expression, such as an assignment or invocation, that does something with the newly defined function.

Read More »