JavaScript Glossary

All coding languages have jargon. Here are some key terms you’ll come across when we talk about JavaScript.

Click on a term below to expand the definition. These are written to help you understand new terminology as you encounter it, for further details refer to MDN Web Docs and have a chat with your Facilitator if you are unsure about anything.

ArgumentsArguments are the value(s) passed into a function when we call it.
function totalNumberOfWinners(parameterOne, parameterTwo, parameterThree) {
return parameterOne + parameterTwo + parameterThree
}
totalNumberOfWinners(10, 36, 2) // output is 48

Here a function is declared/written with three parameters (parameterOne, parameterTwo, and parameterThree – within the round brackets on the first line).

On the last line, the function is ‘called’ and passed arguments 10, 36, and 2. These arguments are the values being passed into the function. They align with the parameters input on the first line.

(Note that sometimes people use the terms parameters and arguments interchangeably, which can be confusing. See Parameters.)

ArraysAn ordered collection of data in which each piece is referred to as an 'element', and can be accessed by its position in the array. This is referred to as the element's 'index'. In arrays the index begins at 0, so the first element is at index 0, the second at 1, and so on.

Arrays are written as comma seperated values, contained within square brackets, e.g. [1, 2, 3]

Arrays can contain strings, numbers, booleans, objects, and even more arrays. You can reference elements within an array by using square bracket notation and the element's index number.

const romanticComedies = [
"You've Got Mail",
"10 Things I Hate About You",
"When Harry Met Sally",
"Sleepless in Seattle"
]
const fourthMovie = romanticComedies[3] // evaluates to: "Sleepless in Seattle"

Above, 'romanticComedies' stores a list of strings. We then access the fourth string in the list using romanticComedies[3], where the '3' represents the fourth element (remember, array indices begin at 0).

Assign/reassign to a variableThe process of assigning values/data to a variable using a single `=` sign. Values are assigned to variables in the first instance, then reassigned if the value needs to change following that.
let smoothie = 'blueberry'
smoothie = 'banana'

Above, on the first line the variable smoothie is being declared, then assigned the value of 'blueberry'. On the second line smoothie is being reassigned the value of 'banana'. After this, smoothie is equal to 'banana' and not 'blueberry'.

Call a function

After declaring/writing a function, you’ll want to use that function! Do that by ‘calling’ it.

function sayYarr() {
return "Yarr!"
}
function pirateBounty(treasureAmount) {
return "Yarr! Ye be " + treasureAmount + " gold coins richer!"
}
sayYarr() // output: 'Yarr!'
pirateBounty(500) // output: 'Yarr! Ye be 500 gold coins richer!'

You call a function by writing its name, followed by brackets (). If the function takes any arguments, the values are placed into these brackets.

In the example above the functions sayYarr and pirateBounty are declared. On the last lines the functions are called. sayYarr does not take any arguments, so is followed by empty brackets. pirateBounty does take an argument, therefore the argument is placed in the brackets. These functions do not run without calling them.

Declare/define a function

Writing a function. For now, you’ll use regular functions which follow a specific format:

function keyword, followed by an identifier/name of the function, then brackets which optionally contain parameters separated by commas, then curly brackets inside of which is the statement(s) that define the function.

function nameOfTheFunction() {
return "Hey there!"
}
function nameOfAnotherFunction(firstParameter, secondParameter) {
return firstParameter + secondParameter
}

Here two functions are being declared/defined using the specific format required.

Execute code

An informal term to describe a piece of code being run.

function saySomething(greeting) {
return greeting
}
saySomething('Hello world!') // output: 'Hello world!'

Above, once this code has run and 'Hello world!' has been returned, we might say "this code was executed".

(Note, you'll often hear people refer to "calling" functions too. See Call a function.)

Expressions

A piece of code that evaluates to a value.

2
// value: 2
4 + 4
// value: 8
'Kia' + ' ' + 'ora'
// value: 'Kia ora'

Above are three expressions followed by comments showing what they evaluate to.

(See also Statements.)

Functions

A piece of code typically used to execute a task, written so that it can be called upon multiple times if needed.

function addTwoNumbers(firstNumber, secondNumber) {
return firstNumber + secondNumber
}
addTwoNumbers(1, 1) // returns: 2
addTwoNumbers(4, 7.5) // returns: 11.5

Above we have declared a function called addTwoNumbers.

Then we have called the function addTwoNumbers twice, with different number values input as arguments. Because the function has already been declared in the first example the logic does not need to be written in full again, it is there ready for us to use.

(See also Declare/define a function, Arguments, Parameters.)

Identifiers

Names of variables, functions, and properties.

The first character must be either:

  • a letter, or
  • an underscore (_); or
  • a dollar sign ($).

The rest of the characters can be numbers, letters, an underscore, or a dollar sign, but the first character cannot be a number (this helps the code run faster).

const treasureMap = 'X marks the spot'
function pirateSurprise() {
return 'Shiver me timbers!'
}

Above, “treasureMap” is the identifier of the variable. "pirateSurprise" is the identifier of the function.

Keyword/Reserved words

All programming languages have keywords. These special words already have a purpose in the language and tell the programme how to behave when it reads that keyword. You cannot use them for other purposes (like naming a variable or function).

For example, the function keyword tells the program that the code that comes after that keyword is a function you (as the coder) are creating. You cannot use the word function anywhere else in your code for anything other than defining a function.

There are about 60+ keywords in JS. Common keywords are let, const, function, if, null, return, switch, this, true/false, for, do, class. You can’t use any of these to label a variable or function.

Code: a function is declared with the name function

Figure 1: The `function` keyword is used, and then the function is given the identifier/name 'function'. The code editor recognises 'function' is an error and helpfully underlines the error with a red squiggle.

Code: error messages telling us function is a keyword so can't be used for anything else

Figure 2: Error messages point out that function is a reserved word, and the function still needs an identifier/name.

Code: a variable is declared and the keyword return is used as the variable name

Figure 3: Line 3: the word return has been used as a variable name, but since it's a keyword the code editor underlines the error with a red squiggle.

Code: error message tells us return can't be used as a variable name

Figure 4: An error message lets us know return is a keyword so can't be used as a variable declaration name.

Methods

Functions that are pre-programmed into the language. They’re shortcuts, so you don’t need to type out long functions for something you frequently use throughout your code.

Example: console.log() is a method. It’s pre-programmed into JS to output a message to the web console. If it didn’t exist, you would need to write it yourself.

Objects

A data type containing unordered (but labeled) key/value pairs, stored within curly brackets {}. Each 'key' acts as a label for the corresponding 'value'.

Key/value pairs are referred to together as a 'property'.

const popcorn = {
foodType: 'movie snack',
price: 4.99,
flavour: 'salt'
}

Above, popcorn is the name of the object. foodType is a 'key', 'movie snack' is a 'value', and together this key/value pair is referred to as a 'property'.

There are multiple ways to access or edit data from inside of an object. One common way to retrieve data from an object is by using dot notation, where we say the name of the object, followed by a dot and then the key we would like to access. For example if we wanted to know the price of popcorn we could use popcorn.price, which provides the value of 4.99. While popcorn.flavour would provide the value of 'salt'.

Parameters

When writing/declaring a function, parameters are the placeholder values used inside the round brackets ( ).

Think of it like parameters = placeholder. Parameters are typically placeholders for values which will be provided as arguments when a function is called.

function totalNumberOfWinners(parameterOne, parameterTwo, parameterThree) {
return parameterOne + parameterTwo + parameterThree
}
totalNumberOfWinners(10, 36, 2) // output is 48

Here a function is declared/written with three parameters (parameterOne, parameterTwo, and parameterThree – within the round brackets on the first line).

On the last line, the function is ‘called’ and passed arguments 10, 36, and 2. These arguments are the values being passed into the function. They align with the parameters input on the first line.

(Note that sometimes people use the terms parameters and arguments interchangeably, which can be confusing. See Arguments.)

Parenthesis/brackets

( ) these are called parentheses (or round brackets/braces).

{ } these are called brackets (or curly brackets/braces) but you may also hear people refer to them as object brackets.

[ ] these are called square brackets (or array brackets).

Return

The return statement stops the execution of a function and returns a specified value to the function caller. Without a return statement a function will return undefined.

function addTogether(num1, num2) {
return num1 + num2
}
addTogether(5, 7) // output: 12

In this example, the function addTogether returns the sum of num1 & num2. If we were to add code after the return statement within this function that code would not be reached or executed.

Statement

A piece of code that performs an action, i.e. an instruction for the browser to carry out.

Most code in a list can be referred to as a statement.

let iceCream = 'Vanilla'
iceCream = 'Mint Chocolate Chip'

Above, on the first line a variable is being declared. On the second line that variable is being reassigned. Each of these lines of code is a statement.

(See also Expressions.)

Variable

How we store data. Think of a variable like a container that holds data.

Use the let or const keywords to declare a variable and an equal sign = to assign values/data to that variable.

let sunrise = '6am'

Above, the variable 'sunrise' is declared and it stores the value/data of '6am'.

(Note, you might also see people declaring variables using they keyword var, but stick to let or const where possible as this is the most modern approach.)