Main Menu

Categories

Subscribe

JavaScript Garbage Collection

March 18th, 2009

Every time a JavaScript program creates a string, array or object, the JavaScript interpreter allocates memory to store one of the three. When memory is dynamically allocated like this, it must eventually be freed up.

With Programming languages like C and C++, the programmer must manually destroy the objects when they are no longer needed.

JavaScript is different, instead of manually freeing up memory by the programmer, It uses a technique called garbage Collection. The JavaScript interpreter can detect when an object will never be used again in the program and frees up the allocated memory used by that object.

No Comments

Primitive & Reference Types in JavaScript

March 18th, 2009

Variables contain values and these values can be any number of datatypes such as a string or boolean etc. these datatypes can be organised into two groups: Primtive & Reference.

Primitive Types: Numbers, Boolean values and the Null and undefined types

A primitive type has a fixed size in memory. A number occupies eight bytes of memory and a boolean value occupies one bit for example. The number type is the largest of the primitive types.

Reference Types: Objects, arrays and functions.

A reference type can be of any size, so it cannot be stored in the eight bytes of memory asociated with each variable. Instead, the variable stores a reference to the value.

No Comments

Variable Scope in JavaScript

March 17th, 2009

The scope of a variable is the region of your program in which it is defined. For example, a global variable has global scope and can be accessed anywhere in your script. A variable defined in a function cannot be accessed outside the function it was created.

No Comments

Declaring Variables in JavaScript

March 15th, 2009

Before you start using variables in Javascript, you have to declare them first by adding the keyword var before the variable name.

Example

var name = "Keith Donegan";

You can also declare multiple with only one var keyword

Example

var name, num, customer;

No Comments

JavaScript Variable Typing

March 15th, 2009

JavaScript is an untyped language, this means that a variable in JavaScript can hold a value of any data-type such as a number, string or boolean etc after it has been declared.

Example

var = 7;
var = true;

No Comments