Basic JavaScript Notes

Don't use document.write

Some of the examples in our textbook, Fundamentals of Web Development, use the document.write function to add information to an HTML document. Using document.write is okay for small examples like that, but you should not use it in your assignment or project code. Instead, use DOM (Document Object Model) functions or the innerHTML property. You can read about using the innerHTML property in the Generating HTML section below.

JavaScript debugging tutorial

Here is a tutorial on debugging JavaScript in a web browser. The tutorial includes a short video demonstration of using the Chrome developer tools.

ES2015 and ES6

Our textbook refers ES2015 which is a (relatively) new version of the ECMAScript standard from 2015. This version of the standard is sometimes referred to as ES6 because it's the sixth major update of the standard. "Traditional" JavaScript is sometimes called ES6.

You can see a list of ES2015 features with explanations and examples at There is a chart showing browser support for ES2015 features at Current versions of Firefox (98%), Chrome (98%), and Safari (99%) support 98-99% of ES2015 features, while current versions of Edge support 96%.

For this class the only things you will be required to know about ES2015 are the features specifically explained in the notes and in the assigned reading in the textbook.


Here are some important things to know about variables in JavaScript:


Strings in JavaScript are immutable. That means once a string is created, it can't be changed.

Generating HTML

You can see an example of generating HTML using strings and the innerHTML property these web pages:
genSample.html A web page with ten h2 headers generated by JavaScript code.
genSample.js The JavaScript code that generates the HTML for genSample.html.
genSampleNotes.html A walk-through of genSample.html and genSample.js

You can see an example of generating HTML using createElement on these pages:
createElement version of the countdown example
JavaScript code for the createElement version of countdown

Using JavaScript outside a web browser

The most common way to execute a JavaScript program is inside a web browser. However, there are other ways to execute JavaScript programs, including server-side scripting in Node.js. Other server-side options are Netscape's web server and Microsoft's IIS web server.

Mozilla provides two JavaScript interpreters--Spider Monkey, which is written in C, and Rhino, which is written in Java. These interpreters can be embedded in other programs, which makes an easy way to add a macro or scripting language to another program. In fact, Version 6.0 of Java includes a JavaScript interpreter, so that any Java 6.0 program can execute JavaScript.