JS Language

Describe to your non-tech friend all the use cases, in the JavaScript language, for each of the following:

parentheses () -These are used to group and contain elements used in statements and functions.

Online definition - Grouping and containing expressions and parameters. Parentheses have multiple functions relating to functions and structures. They are used to contain a list of parameters passed to functions and control structures and they are used to group expressions to control the order of execution. Some functions have no parameters and in this case, the space between parentheses is blank. - reference.

They are used to group expressions in a statement: a = (4 + 3 ) * 2;

They contain expressions in a conditional statement of a formula: if (a > 10) { doSomething};

They can also contain a list of parameters: line(a, 0, a, 100);

Square Brackets [] - These encase declared arrays, and are used when accessing those arryas.

Online definition - The array access operator is used to specify a location within an array. The data at this location can be defined with the syntax array[element] = value or read with the syntax value = array[element]. - reference.

var peopleInClass = ["Tim", "Bridget", "Bob", "Margaret"];

to call "Bob", as Sue's father, from the array: var fatherOfSue = peopleInClass[2];

They can also contain a list of parameters: line(a, 0, a, 100);

Braces {} - These define the beginnning and end of function blocks such as the for() and if() structures. they're also used for defining initial values in array declarations. They wrap around the code defining objects.

myFunction() {doSomething};

int[] a = { 5, 20, 25, 45, 70 };

single quotes '' - These define string literal statements.

var d = "dog";

double quotes "" - The use of these is the same as single quote. Note: consistancy of use is important though, they are not interchangable in one statement.