JavaScript Introduction
JavaScript is one of the most popular programming languages on the web. It is used in millions of web pages to add functionality, validate forms, detect browsers, and much more.
What is JavaScript?
JavaScript is...
- a scripting language
(lightweight programming language) - an interpreted language (not compiled)
- an Object Oriented Programming (OOP) language
- usually embedded directly into HTML pages
- available in all major browsers, such as Firefox, Internet Explorer, Chrome, Opera, and Safari
- NOT Java
JavaScript can be used to make web pages dynamic, react to events, validate data, create cookies, and detect browser information.
JavaScript Tips & Guidelines
The following are important things to know when coding with JavaScript.
Case Sensitivity
JavaScript is case sensitive - therefore ensure the capitalization is correct for variable and function names. A variable named "myIndex" is not the same as "myindex".
Semicolons
Although the JavaScript interpreter automatically adds semicolons to the end of most lines, it is a best practice to add them when writing JavaScript to avoid strange side effects when the interpreter does it automatically.
Whitespace and New Lines
Most whitespace such as spaces, tabs, and empty lines is ignored by the JavaScript interpreter. In general, it is best to use whitespace when coding JavaScript to aid readability.
// These lines are equivalent
x="String";
x = "String";
Breaking a Line of Code
Long lines of code can be broken up with a backslash character as long it is within a text string.
document.write("Hello \
from JavaScript");
Reserved Words
JavaScript reserves certain words for specific uses. The following table lists the JavaScript reserved words:
break | case | catch |
continue | default | delete |
do | else | finally |
for | function | if |
in | instanceof | new |
return | switch | this |
throw | try | typeof |
var | void | while |
with |
The following table lists the reserved for future keywords by the ECMAScript specification:
abstract | boolean | byte |
char | class | const |
debugger | double | enum |
export | extends | final |
float | goto | implements |
import | int | interface |
long | native | package |
private | protected | public |
short | static | super |
synchonized | throws | transient |
volatile |
In addition to the ECMAScript reserved words, certain JavaScript-specific words implemented in most browsers are considered reserved by implementation. The following table lists these reserved keywords:
arguments | Array |
Boolean | Date |
decodeURI | decodeURIComponent |
encodeURI | Error |
escape | eval |
EvalError | Function |
Infinity | isFinite |
Math | NaN |
Number | Object |
parseFloat | parseInt |
RangeError | ReferenceError |
RegExp | String |
SyntaxError | TypeError |
undefined | unescape |
URIError |
JavaScript Statistics
- JavaScript was originally created by Brendan Eich of Netscape in 1995
- JavaScript's formal name is ECMAScript
- JavaScript is governed by the European Computer Manufacturers Association (ECMA), which published the fifth edition of the language in December 2009
- Latest stable version is 1.8.5 (March 22, 2011)
Oracle, Java, and JavaScript are registered trademarks of Oracle Corporation