background preloader

Javascript

Facebook Twitter

A re-introduction to JavaScript. Why a re-introduction?

A re-introduction to JavaScript

Because JavaScript is notorious for being the world's most misunderstood programming language. It is often derided as being a toy, but beneath its layer of deceptive simplicity, powerful language features await. JavaScript is now used by an incredible number of high-profile applications, showing that deeper knowledge of this technology is an important skill for any web or mobile developer. It's useful to start with an overview of the language's history. JavaScript was created in 1995 by Brendan Eich while he was an engineer at Netscape. Several months later, Microsoft released JScript with Internet Explorer 3. Because it is more familiar, we will refer to ECMAScript as "JavaScript" from this point on.

Unlike most programming languages, the JavaScript language has no concept of input or output. Overview JavaScript is a multi-paradigm, dynamic language with types and operators, standard built-in objects, and methods. And there are some built-in Error types as well. Hash Tables in Javascript. Javascript is a prototype-based object-oriented language.

Hash Tables in Javascript

In JavaScript, all non-scalar objects behave as associative arrays, a mapping from property keys to values. The keys and values can be scalars, objects or functions. This tutorial demonstrates how to provide a hash table wrapper around these native objects that avoids stepping on the built-in properties of a JavaScript object and thus makes it more consistent. Introduction A hash table is a permutation of an associative array (i.e. name => value pairs). In JavaScript, all non-scalar objects behave as associative arrays. A short example of an associative array (hash table) in JavaScript is as follows: TIP: Feel free to replace alert() with console.log() if it's supported by your browser (Chrome, Firefox with FireBug, etc). Just as in PHP, the 'foreach' contruct is used to run through the array, doing something for each key => value pair.

Alert('size of hash table ' + h.length); Hmm. Fundamentals h.one h.one = 1; Summary Attributions. Understanding javascript arrays - online javascript primer - creating and storing values in javascript arrays. An array can be regarded as a set of variables.

understanding javascript arrays - online javascript primer - creating and storing values in javascript arrays

This does not mean that the variables in an array are related to each other; they are still separate entities in themselves. Arrays helps us group variables, which we plan to use for a particular purpose because accessing their values becomes a lot easier this way. Consider the following table: To store these city names, we can either employ different variables such as city1, city2, city3 ... or insert these values into an array. Let's see how we make an array. var city = new Array(); Each array is initialized using the new keyword with the Array() construct (Isn't this similar to using Date()?).

City[0] = "New York"; city[1] = "London"; city[2] = "New Delhi"; city[3] = "Sydney"; city[4] = "Tokyo"; city[5] = "Moscow"; city[6] = "Lima"; Each variable in an array begins with the array name followed by a numeric value contained in a pair of square brackets. JavaScript allows us to write the array initialization and assignment statements as one. A JavaScript Primer in Four Parts. JavaScript Primers, Tutorials and Scripts from HTMLGoodies. JSDB: JavaScript for databases.