JS Basics/ES5 Flashcards
How many data types are there in JavaScript?
Name them.
8:
undefined
null
boolean
string
symbol
bignit
number
object
How is a variable declared in JS? Give an example.
We declare a variable by putting the keyword var in front of it:
var myName;
How are statements ended in JS?
With a semicolon (;).
What are the rules for variables’ naming?
Variable names can be made up of numbers, letters, and $ or _, but may not contain spaces or start with a number.
What is the diffence between declaring and initialising a variable? What is the quickest way to do both?
Declaring is creating (naming) a variable. Initialising in assigning a value to the variable for the first time.
The quickest way to do both is to do them in one line:
var myName = “anti”;
or
var myNumber = 7
What is a string literal?
A series of zero or more characters enclosed in single or double quotes.
What is the default value of an declared but not initialised variable?
What message do you get when you try to use a mathematical operation involving such a variable?
What about string concatenation?
undefined
for mathematical: NaN (Not a Number)
for concatenation: undefined
Is JS case sensitive?
Yes.
What is best practice in naming variables?
Give an example.
Write variable names in JavaScript in camelCase. In camelCase, multi-word variable names have the first word in lowercase and the first letter of each subsequent word is capitalized.
Example:
var someVariable;
What is the difference between var and let?
When a variable is declared using the var keyword, it can be re-declared without throwing an error; but when the let keyword is used, each variable must have unique names i.e. trying to re-declare it with the same name will thow an error.
How is a read-only variable declared?
Give an example.
Use the const keyword.
Example:
const myReadOnlyVariable;
Compare the kewords const and let in JS.
const has all the features of let but it is read-only.
What is best practice in naming constants (variables that are not supposed to be changed)?
Should be all upper case.
What are two other names for decimal numbers in JS?
Floating point numbers or just floats
In JS, what is the remainde operation symbol? What does it do?
%
It returns the remainder of a division: e.g. 5%2 = 1
What is the most common usage of the remainder operation?
To find out if a number is even or odd. If the remainder is zero then the number is even.
Comment on remainder vs modulus.
They are not the same.
The remainder does not work well with negative numbers.
In programming, which side of an operation in evaluated first?
The right side of the assignment.
What do the += and -= operators do?
What about *= and /=?
They add or subtract what’s on the right-hand side to or from the variable on the left-hand side of the operator, respectively.
The others do the same but with their respective operations.
E.g. myVar *= 3; is the same as myVar = myVar * 3;
In JS, how can you place quotes inside quotes?
By using the escape () symbol before the inner quotes.
Comment on the use of single vs double quotes in JS.
They can both be used to create string literals as long as the string starts and ends with the same type of quote.
What are the 8 most common uses of the escape character?
' - single quote
" - double quote
\ - backslash
\n - new line
\t - tab
\r - carriage return
\b - word boundary
\f - form feed
In JS, when you use a + with Strings, what is it called?
Concatenation
Can we use += and *= in concatenation?
Yes.























































