JavaScript language

Parentheses ( )

Parentheses are uses for a few different functions, here are some examples below

Grouping expressions:

a + (b * c)

Containing expressions:

(x % 2 == 0)

Containing a list of parameters:

functionName(parameter1, parameter2, parameter3) { code to be executed}

Brackets [ ]

Square brackets provide access to an object’s properties, for example, bracket notion:

object[“property”]

Arrays contain a list of data, which is wrapped in square brackets:

var cars = [“Saab”, “Volvo”, “BMW”];

Arrays within arrays:

var items = [[1, 2],[3, 4],[5, 6]];

Single quotes '' & Double quotes “”

It important to understand how to use quotes appropriotly in JS. We should use single quotes where you want double quotes to appear inside the string, (e.g. for a html attributes), without having to escape them, or vice versa. Other than that, there is no difference. He is an example.

var answer = "He is called 'Johnny'"; var answer = 'He is called "Johnny"';

Either single or double can be used, as long as you are consistant. Below is am example of an object itural, in single quotes:

var myObject = { prop_a: ‘some string value’, prop_b: ‘string value’, int_prop: 100 };

Either double or single can be used, as long as you are consistant. Example of double quotes:

var carname = “Volvo XC60”;

image js code