JavaScript Review

JavaScript

The script Element

Basic Syntax

Simple Example

<!DOCTYPE html>
<html>
<head>
  <title>Hello World</title>
</head>
<body>
  <script>
    document.write("Hello World");
  </script>
  <noscript>
    Your browser does not support or has 
    disabled JavaScript
  </noscript>
<body>
</html>

JavaScript Variable Naming Rules

JavaScript Types

The String Type

String Interpolation

Multi-line strings

Arithmetic Operators

Operator Description Example
+ Addition a + 3
- Subtraction a - 3
* Multiplication a * 3
/ Division a / 3
% Modulus a % 3
++ Increment ++a
Decrement –a

Assignment Operators

Operator Example Equivalent to
= a = 3 a = 3
+= a += 3 a = a + 3
+= a += 3 a = a + "text"
-= a -= 3 a = a - 3
*= a *= 3 a = a * 3
/= a /= 3 a = a / 3
%= a %= 3 a = a % 3

JavaScript Implicit Type Coercion

Explicit Type Casting Functions

Equality & Comparison Operators

Operator Description Example
== equal to a == 3
=== identical to a === 3
!= not equal to a != 3
!== not identical to a !== 3
> greater than a > 3
< less than a < 3
>= greater than or equal to a >= 3
<= less than or equal to a <= 3

Logical Operators

Operator Description Example
&& and a == 3 && b == 0
|| or a == 3 || b == 0
! not !(a == b)

Selection

Iteration

Defining a JavaScript Function

function function_name([parameter [, ...]])
{
    // Statements

    [return]
}

Variable Scope

JavaScript Objects

JavaScript Object Literal Syntax

object_name = {
    property1: value1,
    property2: value2,
    method1: function (parameters) {
        function_body
    }
};

Accessing Object Properties and Methods

JavaScript Numeric Arrays

Some JavaScript Array Methods

JavaScript Associative Arrays