Javascript Flashcards
What is the purpose of variables?
Used to hold data for scripting
How do you declare a variable?
Use the keyword var then the name you want to give to the variable
How do you initialize (assign a value to) a variable?
with the “=” sign.
What characters are allowed in variable names?
letters, numbers, _, $
What does it mean to say that variable names are “case sensitive”?
var Apple is different then var apple
What is the purpose of a string?
Strings hold information in text form.
What is the purpose of a number?
numbers hold information in numerical form.
Used for math
What is the purpose of a boolean?
to declare if something is true or false. Used for conditionals
Allow us to make decisions in code.
What does the = operator mean in JavaScript?
Is being assigned to
How do you update the value of a variable?
write the name of the variable with a different value
What is the difference between null and undefined?
null is purposeful emptiness. (declared by developer)
undefined is accidental emptiness. (declared by javascript)
Why is it a good habit to include “labels” when you log values to the browser console?
Helps with debugging.
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
To join 2 or more strings together.
What purpose(s) does the + plus operator serve in JavaScript?
can be used for arithmetic expressions and also string concatenation.
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds the value and assigns that result to original value.
ex: x+=y // x = x + y
What are objects used for?
to store data with multiple properties(pieces of data) in a variable.
What are object properties?
individual piece of named data within an object.
Describe object literal notation.
declare the variable name it, “{
and key: value,
key: value,
};
object, key, value
How do you remove a property from an object?
use the delete keyword followed by the object name and property name
delete object.property;
What are the two ways to get or update the value of a property?
object.property = ‘updated value’
object[‘property’] = ‘updated value’
dot notation and square bracket notation.
What are arrays used for?
It is used to store a list of information/values.
Describe array literal notation.
array = [ ‘one’, ‘two’, ‘three’];
How are arrays different from “plain” objects?
Values of an array are almost always the exact same data type.
Has a length property as default.