Basic JavaScript Flashcards
learn the basics
- Comment Your JavaScript Code:
How do you comment a single line?
How do you comment multiple lines?
//
/………………./
- Declare JavaScript Variables:
What are the 7 data types?
What can variable names be made up of?
What can variable names not contain or start with?
undefined, null, boolean, string, symbol, number and object.
Variable names can be made up of numbers, letters, and $ or _,
Variable names cannot contain spaces or start with a number.
- Storing Values with the Assignment Operator:
How do you assign a variable?
Which way does assignment go?
myVariable = 5;
This assigns the Number value 5 to myVariable.
Assignment always goes from right to left.
Everything to the right of the = operator is resolved before the value is assigned to the variable to the left of the operator.
- Initializing Variables with the Assignment Operator:
How do you assign the value of 0 to myVar?
var myVar = 0;
Creates a new variable called myVar and assigns it an initial value of 0.
- Understanding Uninitialized Variables:
What is the initial value of variables when they are declared?
What happens when you do a mathematical operation on an undefined variable?
What happens when you concatenate a string with an undefined variable?
When JavaScript variables are declared, they have an initial value of undefined.
If you do a mathematical operation on an undefined variable your result will be NaN which means “Not a Number”.
If you concatenate a string with an undefined variable, you will get a literal string of “undefined”.
- Understanding Case Sensitivity in Variables:
MYVAR not the same as MyVar or myvar
What is camelCase?
var myVar;
var someVariable;
var anotherVariableName;
- Add Two Numbers with JavaScript:
Number is a data type in JavaScript which represents numeric data.
How do you assign a variable that adds 5 + 10?
myVar = 5 + 10; // assigned 15
- Subtract One Number from Another with JavaScript:
How do you assign a variable that subtracts 6 from 12?
myVar = 12 - 6; // assigned 6
- Multiply Two Numbers with JavaScript:
How do you assign a variable that multiplies 13 by 13?
myVar = 13 * 13; // assigned 169
- Divide One Number by Another with JavaScript:
How do you assign a variable the divides 16 by 2?
myVar = 16 / 2; // assigned 8
- Increment a Number with JavaScript:
You can easily increment or add one to a variable with the ++ operator.
What is the equivalent of i = i + 1;?
i++;
- Decrement a Number with JavaScript:
You can easily decrement or decrease a variable by one with the – operator.
What is the equivalent of i = i - 1;?
i–;
- Create Decimal Numbers with JavaScript:
We can store decimal numbers in variables too. Decimal numbers are sometimes referred to as floating point numbers or floats.
Create a variable myDecimal and give it a decimal value with a fractional part (e.g. 5.7).
var myDecimal = 5.7;
- Multiply Two Decimals with JavaScript:
In JavaScript, you can also perform calculations with decimal numbers, just like whole numbers.
Multiply two decimals together to get their product?
var product = 2.0 * 0.0;
- Divide One Decimal by Another with JavaScript:
Change the first decimal so that the quotient will equal to 2.2.?
var quotient = 4.4 / 2.0;