Loops, Conditional Statements, Functions, Variables, Parameters, Arrays, Associative Arrays

Variables, Functions and Parameters

JavaScript variables are containers for storing data values.

A JavaScript function is a block of code designed to perform a particular task.

Function parameters are the names listed in the function definition.

Here's an example that uses a function to calculate wind chill:

Temperature:
Wind Speed:

Wind Chill:

Loops

Loops can execute a block of code a number of times.

Here's an example of a function that uses a while loop to print out the times table for the number 5:


Here's an exaple of a for loop that iterates over an array:


Conditional Statements

Conditional statements are used to perform different actions based on different conditions.

Here's an example of a function using conditional statements that will print out whether it's the weekend:


Arrays and Associative Arrays

JavaScript arrays are used to store multiple values in a single variable.

In this example we can see a function that uses an array to print out a sum of the first and last number in the array [1, 2, 3, 4, 5, 6]:


Sum:

An associative array isa set of key value pairs.The key can be either an identifier, a string or a number. The value stored can be any JavaScript object.

Here's an example of an associative array: