Sunday, September 18, 2011

JavaScript I - Initial Concepts

Basic Information

  • JavaScript is a case-sensitive language. Many client-side JavaScript objects and properties have the same names as the HTML tags and attributes they represent. While these tags and attribute names can be typed in any case in HTML, in JavaScript they typically must be all lowercase.
  • JavaScript’s strings (and its arrays) use zero-based indexing.
  • When the JavaScript interpreter starts, it creates a new global object that has: Properties like undefined, Infinity, and NaN , Functions like isNaN(), parseInt(), and eval(), Constructor functions like Date(), RegExp(), String(), Object(), and Array() and Global objects like Math and JSON.
In client-side JavaScript, the Window object serves as the global object for all JavaScript code contained in the browser window it represents. This global Window object has a self-referential window property that can be used instead of this to refer to the global object.

Primitive values

Primitives are immutable: there is no way to change (or “mutate”) a primitive value. Primitives are also compared by value: two values are the same only if they have the same value. The primitive values are:
  • Numbers, strings, or booleans.
  • null and undefined.

Numbers

Arithmetic in JavaScript does not raise errors in cases of overflow, underflow, or division by zero. Check the following table:
Case Result
Overflow It could be either:Infinity or -Infinity
Infinity as one operand It could be either:Infinity or -Infinity
Division by Zero It could be either:Infinity or -Infinity
0/0 NaN
For more complex mathematical operations check the Math object.

Boolean values

The Boolean values are: true and false, aside of that when a value different from boolean has to be converted to one JavaScript  converts it to true or false base on the following table:
Values Convert to
undefined, null, 0, –0, NaN, "" false
All other values, including all objects (and arrays) true

null and undefined

Both does not neither properties nor methods and indicate an absence of value. Comparing both using “==” we will get “true”
null undefined
Description It is a language keyword It is the value of variables that have not been initialized. The value you get when you query the value of an object property or array element that does not exist. It is also returned by functions that have no return value, and the value of function parameters for which no argument is supplied.
Represent Program-level, normal, or expected absence of value system-level, unexpected, or error-like absence of value
typeof "object" "undefined"

Object

It is a collection of properties where each property has a name and a value. an unordered collection of named values. It is mutable.

Objects are not compared by value, are compared by reference: two object values are the same if and only if they refer to the same underlying object. Core JavaScript defines the following useful classes.

Name Definition
Array Represents an ordered collection of numbered values.
Function A function is an object that has executable code associated with it.
Date Defines objects that represent dates.
RegExp Defines objects that represent regular expressions.
Error Defines objects that represent syntax and runtime errors that can occur in a JavaScript program.

0 comments:

Post a Comment