JavaScript Flashcards
What is the purpose of variables?
To store data that we can go back to later. Permanence of data
How do you declare a variable?
var (variable name) then assignment operator (=) with variable value
How do you initialize (assign a value to) a variable?
var keyword then variable name with the assignment operator (=)
What characters are allowed in variable names?
$, letters, numbers, underscore (variable can’t begin with number
What does it mean to say that variable names are “case sensitive”?
words with lower case and upper case are completely separate things to JavaScript
What is the purpose of a string?
To store characters in a row that JavaScript won’t read as code
What is the purpose of a number?
To store numeric values
What is the purpose of a boolean?
Act as an “on or off” switch (indicating true or false)
What does the = operator mean in JavaScript?
Assignment operator to give something value
How do you update the value of a variable?
You just redeclare that variable as normal, except without the keyword “var”, “let”, or “const”
What is the difference between null and undefined?
undefined is the way JavaScript creates or says something is empty or has no value (empty area which could have been left empty for random reasons)
null is something that we HAVE assign to make something empty or have no value (empty parking lot is on purpose so we can fill it with cars)
Why is it a good habit to include “labels” when you log values to the browser console?
So that we can identify what exactly we are using the console.log method on.
Give five examples of JavaScript primitives.
String, boolean, null, undefined, and numbers
What data type is returned by an arithmetic operation?
number data type
What is string concatenation?
it’s using the plus sign operator to combine two or more strings together
What purpose(s) does the + plus operator serve in JavaScript?
it’s used for string concatenation or adding numbers together
What data type is returned by comparing two values (, ===, etc)?
a boolean
the strict equality operator (three equal signs) checks for same value and type
What does the += “plus-equals” operator do?
it adds the value of the right operand and a variable, then it assigns the result of that expression to the variable.
so a += 3 is the same as “var a = (a’s old value) + 3”
What are objects used for?
objects are used to store a collection of data
What are object properties?
object properties are the keys
Describe object literal notation.
keyword ‘var’ followed by a name then ‘=’ followed by curly brackets ‘{ }’
How do you remove a property from an object?
keyword ‘delete’ followed by object.property
What are the two ways to get or update the value of a property?
bracket notation or dot notation
What are arrays used for?
For representing lists of data