JavaScript

JavaScript is a dynamically typed imperative programming language with functional features. JavaScript is the main language for programming web pages; however it's use as a general purpose programming language is growing.

JavaScript is generally interpreted.

Why would I learn this language?

JavaScript is the language of the internet. To create an interactive website, JavaScript is the best choice. The web browser is a very capable application development platform and is available for the majority of platforms.

JavaScript has excellent debugging tools and due to the nature of its execution environment, provides a rich set of elements (such as images, audio and text) for displaying results.

JavaScript is a semantically simple language with first-class functions. This makes it very easy to use advanced functional concepts.

Starting Points

Eloquent JavaScript
An interactive online tutorial for the beginner programmer.
Learning Advanced Javascript
A set of tutorials covering advanced computer programming topics in JavaScript.
Firebug
A fantastic tool for developing and debugging JavaScript in FireFox.
Mozilla Developer Network
A great set of resources and documentation for programming JavaScript in the web browser.
jQuery
A fantastic toolbox for writing simple cross-browser JavaScript code. Includes support for many advanced features.

Example Code

The following is an example of the Fizz Buzz problem. You can run and edit this program here.

for (var i=1; i <= 100; i++) {
    if (i % 3 == 0 && i % 5 == 0) {
        console.log("FizzBuzz");
    } else if (i % 3 == 0) {
        console.log("Fizz");
    } else if (i % 5 == 0) {
        console.log("Buzz");
    } else {
        console.log(i);
    }
}

The following is an example of the 100 doors problem. You can run and edit this program here.


function doors (n) {
	// Create an array with 100 objects
	var is_open = [];
 
	// Initialize the array values to false
	for (var i = 0; i < n; i++) {
		is_open[i] = false;
	}
 
	// Process the doors
	for (var step = 0; step < n; step += 1) {
		for (var idx = step; idx < n; idx += step+1) {
			is_open[idx] = !is_open[idx];
		}
	}

	// Print the results
	for (i = 0; i < n; i++) {
		if (is_open[i]) {
			console.log("Door #" + (i+1) + " is open.");
		} else {
			console.log("Door #" + (i+1) + " is closed.");
		}
	}
}

doors(100);

Further Reading

comments powered by Disqus