Blog

Introduction to JavaScript Programming – part 2

Introduction to JavaScript Programming – part 2: Continuing from Introduction to JavaScript Programming – part 1.

In previous part I just gave an introduction to JavaScript Programming, and also I explained what is a variable in JavaScript. In this part we are going to discuss about JavaScript Strings and JavaScript Arrays.

JavaScript Strings

If you need to concatenate two or more strings, use the + operator.
example

- If you place a quotation mark within a string, it may cause an error. To use a quotation mark within a string, use the escape code “.

example

Escape Codes Used by JavaScript

JavaScript Arrays

An array is list or table of variables of the same data type. For example to create an array containing the names of colors you might use the code below.

Access an element of an array by using its index. For example to access the array element “orange”, use the code below.

Notes:
- The first element in the array always has an index of 0. The last element in an array has an index one less than the size used to declare the array.
- You can declare and initialize an array at the same time as shown below.

If you don’t know how many elements will be in the array, you can declare it without a size as shown below.

This note will continue in Introduction to JavaScript Programming – part 3 page