Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

JS 2009 (ES5)

ECMAScript 2009, or ES5, was the first major update to JavaScript.

This chapter covers the key features introduced in ES5.

ES5 Features

  • “use strict”
  • String[number] access
  • Multiline strings
  • String.trim()
  • Array.isArray()
  • Array forEach()
  • Array map()
  • Array filter()
  • Array reduce()
  • Array reduceRight()
  • Array every()
  • Array some()
  • Array indexOf()
  • Array lastIndexOf()
  • JSON.parse()
  • JSON.stringify()
  • Date.now()
  • Date toISOString()
  • Date toJSON()
  • Property getters and setters
  • Reserved words as property names
  • Object.create()
  • Object.keys()
  • Object management
  • Object protection
  • Object defineProperty()
  • Function bind()
  • Trailing commas

Browser Support

ES5 (JavaScript 2009) has been fully supported in all modern browsers since July 2013.

js 4

The “use strict” Directive

The “use strict” directive enforces “strict mode” in JavaScript.

 

In strict mode, for instance, using undeclared variables is not allowed.

You can apply strict mode to all your programs to help write cleaner code, such as preventing the use of undeclared variables.

 

The “use strict” directive is simply a string expression, and older browsers won’t throw an error if they don’t recognize it.

Property Access on Strings

The charAt() method returns the character at a specified index (position) within a string.

Example

var str = “HELLO WORLD”;
str.charAt(0);            // returns H

ES5 allows accessing properties on strings.

Example

var str = “HELLO WORLD”;
str[0];                   // returns H

Strings Over Multiple Lines

ES5 allows string literals to span multiple lines if they are escaped with a backslash.

Example

“Hello \
Dolly!”
;

A safer way to break up a string literal is by using string concatenation.

Example

“Hello “ +
“Dolly!”;

Reserved Words as Property Names

ES5 allows reserved words to be used as property names.

Object Example

var obj = {name: “John”new“yes”}

String trim()

The trim() method removes whitespace from the beginning and end of a string.

Example

var str = ”       Hello World!        “;
alert(str.trim());