JavaScript Flashcards
What is the purpose of variables?
to store data/ information that the script will use later
How do you declare a variable?
var, let, const
How do you initialize (assign a value to) a variable?
var variableName = value;
What rules are allowed in naming variable names?
must begin with letter, $, or _ and must NOT start with a number
can contain characters above but not - or .
cannot use existing keywords like var
case sensitive
camel case
What does it mean to say that variable names are “case sensitive”?
score != Score
What is the purpose of a string?
to include text data such as names… etc characters
What is the purpose of a number?
to store numerical data, integers…. decimals..
What is the purpose of a boolean?
to store logical data, true false, 1 and 0,
What does the = operator mean in JavaScript?
assignment operator, assigns value to variables
How do you update the value of a variable?
by recalling the variable name and assigning with a new value after the first assignment line
var number = 1;
number = 2;
console.log(number)
>2
What is the difference between null and undefined?
difference is that null is derived from an object and points to non-existent/ invalid object
undefined is a value assigned to variables that have not been assigned a value
null says the there is no box in existence, undefined says the box is empty
null is assigned to be empty on purpose –> “empty”
never assign anything with undefined
Why is it a good habit to include “labels” when you log values to the browser console?
to specify what the varible the input is coming from
Give five examples of JavaScript primitives.
number string boolean null undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combining string values using + arithmetic operator
What purpose(s) does the + plus operator serve in JavaScript?
addition operator and string concatenation
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
addition assignment, adds left side to value to variable current value.
What are objects used for?
objects are used to provide properties or characteristics to one ‘object’
What are object properties?
variables of that object that describe a value
Describe object literal notation.
{ property: value, …. }
How do you remove a property from an object?
delete object.property
What are the two ways to get or update the value of a property?
object.property = new value object['property'] = new value
What are arrays used for?
to store a list of items or objects