seal Object function



semicolon insertion

The rules for placement of ; semicolon at the end of a statement are a little complicated because some statements require it and some do not. The language provides a mechanism called semicolon insertion that makes it possible to leave out ; semicolon in many (but not all) situations. The semicolon insertion feature was intended to make the language simpler, but it actually makes it more complicated and fragile. There are three cases when semicolons are inserted.

It is necessary that the expression part of a return statement begin on the same line as return. For example,

function seconds(day, hour, minute, second) {

// This function will fail in a surprising way.

        day    * 86400 +
        hour   *  3600 +
        minute *    60 +

The value returned by seconds is always undefined, because a ; semicolon is inserted between return and day. In this case, that behavior is clearly undesirable, but there is no way to turn semicolon insertion off.

In the next example, a ; semicolon is not inserted after c because there is not a syntax error.

a = b + c
(d + e).print()

It is understood to mean

a = b + c(d + e).print();

which might be quite different than the intention, so it is not wise to rely on semicolon insertion. It can mask errors and it can cause errors.

These statements should always end in ; semicolon:

Fortunately, it is a short list and is not difficult to remember. The situation is made more complicated because some of the other statements, such as if statement and while statement, are compound statements that take a block or another statement, and that other statement might also end in ; semicolon. That confusion is easily avoided by always using a block.

When assigning a function literal using = assignment infix operator in an expression statement or var statement, the statement should end with a ; semicolon. So this statement should end with ; semicolon:

var double = function (number) {
    return number * 2;

It resembles a function statement, which does not end with ; semicolon, but it is a var statement, and a var statement always ends with ; semicolon.




See object.


setDate Date prototype function



setFullYear Date prototype function



setHours Date prototype function



setMilliseconds Date prototype function



setMinutes Date prototype function



setMonth Date prototype function



setSeconds Date prototype function



setTime Date prototype function



setUTCDate Date prototype function



setUTCFullYear Date prototype function



setUTCHours Date prototype function



setUTCMilliseconds Date prototype function



setUTCMinutes Date prototype function



setUTCMonth Date prototype function



setYear Date prototype function



shift Array prototype function



sin Math function sine

The Math.sin(radians) function, also known as sine, takes an angle in radians and returns a number in the range -1...1.

function cartesian(distance, radians) {

// Given a distance and direction from the origin in radians,
// produce a cartesian point.

    return {
        x: distance * Math.cos(radians),
        y: distance * Math.sin(radians)

This is an approximate implemention of Math.sin:

Math.sin = (function () {
    var factorial = 1,
        last_stage = 40,
        sign = -1,
        signed_factorial_recipricals = [],
        two_pi = Math.PI * 2;

    for (stage = 3; stage < last_stage; stage += 2) {
        factorial *= (stage - 1) * stage;
        signed_factorial_recipricals[stage] = sign / factorial;
        sign = -sign;
    return function sin(radians) {
        while (radians >= two_pi) {
            radians -= two_pi;
        while (radians < 0) {
            radians += two_pi;
        var result = radians,
            rr = radians * radians,
        for (stage = 3; stage < last_stage; stage += 2) {
            radians *= rr;
            result += radians * signed_factorial_recipricals[stage];
        return result;

See Math function.


slice Array prototype function


slice String prototype function



some Array prototype function



See the ! " $ % & ' ( ) * + , - . / : ; < = > ? [ \ ] ^ _ { | } ~ Division.


splice Array prototype function



split String prototype function



sqrt Math function square root

Math.sqrt(number) is the square root function. It returns a value which, when multiplied by itself, is approximately equal to the original number. It could be implemented as

Math.sqrt = function (number) {
    return Math.pow(number, 0.5);
function distance(a, b) {

// Compute the distance between two points.

    return Math.sqrt(Math.pow(a.x - b.x, 2) + Math.pow(a.y - b.y, 2));


SQRT1_2 Math number square root of 0.5

Math.SQRT1_2 holds the result of Math.sqrt(1 / 2), which is approximately 0.7071067811865476.


SQRT2 Math number square root of 2

Math.SQRT2 holds the result of Math.sqrt(2), which is approximately 1.4142135623730951.

square root

See sqrt Math function square root




A statement is a syntactic unit of execution. A compilation unit or a function body contains a list of zero or more statements which will be executed in order from first to last. Each statement runs to completion before the next statement is executed. Some statements can contain other statements. These are the kinds of statements:

Also see ; semicolon, conditional statement, disruptive statement, and loop statement.

static reserved word


The ES5/strict dialect removes or modifies a few of the language’s most problematic features. It requires source-level opt-in in order to not break compatibility. It is recommended that strict mode always be requested.

Because strict mode can break compatibility with ES3, it must be explicitly requested with the strict mode pragma. The pragma takes the form of a string literal expression statement:

"use strict";

It will be ignored by ES3 processors, so it is possible to create ES5/strict programs that will work correctly in ES3 processors. The strict mode pragma can be placed at the top of a compilation unit, or as the first statement of a function body. When placed at the top of a compilation unit, it indicates that the entire compilation unit is to be treated strictly. This is the preferred usage. When placed at the top of a function body, it indicates that the function is to be treated strictly. It is possible to mix strict mode code and non-strict mode code. Functions compiled in either mode can call functions compiled in the other mode.

* whether a failed property assignment or deletion fails silently or noisily (with a thrown error).

* Although strict code may say "delete global.Object", it may not say "delete Object". Nonstrict code may say either.

* If the global "Object" property is already deleted and the global object is extensible, then, although strict code can say "global.Object = 8;" or (at top level) "var Object = 8;" or "function Object...", simply saying "Object = 8" will fail. All four will succeed in nonstrict code.



A string is a finite ordered sequence of zero or more characters. A character is a 16 bit Unicode code unit. A string is immutable, so once a string is made, it cannot be changed. Two strings containing the same code points in the same order will be found to be equal by the === infix operator. The typeof prefix operator produces 'string' when its operand is a string. Two strings can be combined to produce a new sting with the + infix operator add or concatenate.

'cat' === 'c' + 'a' + 't'    // true

A string contains a length property that produces a number which is the number of code units in the string. There is no fixed limit on the size of a string.

"".length                   // 0
('c' + 'a' + 't').length    // 3

A string value inherits from String.prototype. This provides methods such as charAt String prototype function that can fetch a single character from a string, or slice String prototype function that can fetch a substring from a string. See String prototype function.

A string can contain any kind of textual material, including programs.

There is no separate character type. A single character is represented as a string with a length of 1.

String global function

String is a global function that serves three purposes.

First, when invoked as a function, it takes any operand and produces a string value.

Second, when invoked as a constructor with the new prefix operator, takes an operand and produces an object whose valueOf method produces a string value.

Third, it has a prototype property that holds the methods that are inherited by all strings.

string literal

A string literal is used to include a string value in a program. There are two forms of string literal: single quote string literal and double quote string literal. They differ only in the character used to wrap the characters.

A string literal is a token made up of a quoting character, zero or more character literals, and a matching quoting character.

The quoting characters are

A character literal can be

A Unicode escape sequence is a \u followed by 4 hexadecimal digits. The digits are evaluated in base 16 to produce a single 16 bit code unit.

A compact escape sequence is a \ backslash followed by one of the following:

Character after \ The resulting character
' single quotation mark ' single quotation mark
" double quotation mark " double quotation mark
\ backslash \ backslash
b bs (\u0008) backspace
f ff (\u000c) formfeed
n lf (\u000a) line feed
r cr (\u000d) carriage return
t ht (\u0009) horizontal tabulation
v vt (\u000b) vertical tabulation
x 2 hexadecimal digits A character between \u0000 and \u00ff
line terminator line continuation

These all represent the same string:

'"'  "\""  '\x22'  "\u0022"

If the character after the \ backslash is a line terminator or the line terminator pair cr lf, then the line terminator (or line terminator pair) will be ignored. This produces line continuation, permitting a string literal to be continued over more than one line. Be careful, it can be tricky: If the character following the \ backslash is ordinary whitespace and not a line terminator, then a syntax error will result. All whitespace looks alike.

    var long_line_1 = "This is a \
long line";                         // ok
    var long_line_2 = "This is a \
long line";                         // syntax error

ES3 does not allow line continuation.

There is no limit on the length of a string literal. The empty string can be represented as '' or "".

Because there are two forms of string literal, there is confusion about which to use. The language itself is completely neutral on this question, but there are some principle of good practice to consider:

String prototype function



stringify JSON function



substr String prototype function



substring String prototype function



See - infix operator subtract.

suffix operator


Also see assignment suffix operator.

super reserved word

switch reserved word

switch statement



SyntaxError global function