Chapter 2 - Basic Javascript Instructions Flashcards
A statement is…
An individual instruction or step in a script e.g. var today = new Date();
Is Javascript case-sensitive?
Yes
Give a detailed description of a statement…
A statement is an individual instruction that the computer should follow.
Each one starts on a new line and ends with a semicolon
The semicolon lets the JS interpreter know when the statement is over, and that it should move on to the next step.
What is a code block?
A statement surrounded by a curly brace.
The closing curly brace is not followed by a semicolon
Code blocks will often be used to group together many statements.
This helps programmers organise their code and make it more readable.
Why write comments?
Comments help to explain what your code does
They help make your code easier to read and understand.
This can help you and others who ead your code.
How would you write a single-line comment?
A single line comment would be anything on a line that follows two forward slash characters
How would you write a multi-line comment?
You start with a /*
You end with a */
Anything between these two is not processed by the JS interpreter
When might you use a multi-line comment?
To describe how a script works
To stop a section of your script from running when testing it.
What is a variable?
A variable is a piece of information that a script needs to store temporarily so that it can do its job.
How would variables factor in the calculation of the area of wall?
You would need to multiply the width and the height of a wall to calculate its area
Variables would be used to temporarily store values for the height and width.
Which type of human memory might you compare variables to?
Short-term memory
If you have a script which can calculate the area of a wall, which part of this task is best represented by variables?
Variables are best used to represent the values in your script that are likely to change
In this case, it would be the specific heights and widths of each wall
Even though these change, the area of a wall will always be height x width.
What kind of data is generated by variables, when used together in a script?
Calculated or computed data.
How is a variable declared?
var is a keyword that the interpreter recognises and anticipates the creation of a variable
The variable must be given an identifier e.g. quantity in var quantity.
Give an example of how you would declare a variable?
var quantity;
How would you write a variable name of more than one word?
You would use camelCase
What does it mean to assign a value to a variable?
Telling a variable what information you want it to store for you.
What are some good practices when naming variables?
A variable name should describe the kind of data that the variable holds.
What is the significance of the equals (=) sign?
This is known as the assignment operator
It can assign or update the value given to a variable
If a variable is declared, but has now value assigned, it is said to be…
Undefined.