JavaScript Flashcards
(196 cards)
What is the purpose of variables?
To store data and information to be used for later
How do you declare a variable?
By using the var keyword and giving it a variable name
How do you initialize (assign a value to) a variable?
By using the “=” sign (assignment operator)
What characters are allowed in variable names?
Letters, numbers, dollar signs ($), or an underscore (_)
What does it mean to say that variable names are “case sensitive”?
Score and score are different variable names. Lowercase and Uppercase are different
What is the purpose of a string?
Add new text content into a page
What is the purpose of a number?
Represent numerical values. They are good for tasks that involve counting or calculating sums.
What is the purpose of a boolean?
Helpful when determining which part of a script should run.
What does the = operator mean in JavaScript?
Assignment operator
How do you update the value of a variable?
Assign a new variable value but with a different value. Don’t use the var keyword
What is the difference between null and undefined?
Null means an empty or non-existent value. Null is assigned, and explicitly means nothing.
Undefined means a variable has been declared, but the value of that variable has not yet been defined.
Why is it a good habit to include “labels” when you log values to the browser console?
It is much clearer which variables are being logged. If you do not include “labels”, it can be very confusing instead of helpful.
Give five examples of JavaScript primitives.
String, number, undefined, boolean, null
Primitives are stored data/values.
What data type is returned by an arithmetic operation?
A number
What is string concatenation?
The process of joining together 2 or more strings to create one new string
What purpose(s) does the + plus operator serve in JavaScript?
It adds numbers or concatenate strings
What data type is returned by comparing two values (, ===, etc)?
A boolean
What does the += “plus-equals” operator do?
adds the value of the right operand to a variable and assigns the result to the variable
What are objects used for?
group together a set of variables and functions to create a model of something you would recognize from the real world.
What are object properties?
A variable that is part of an object. Properties tell us about the object.
Describe object literal notation.
To access a property or method of an object you use the name of the object, followed by a period, then the name of the property or method you want to access.
How do you remove a property from an object?
Use the delete keyword and then use dot notation to identify the property or method you want to remove from the object
delete user.firstName
What are the two ways to get or update the value of a property?
Dot notation or square brackets
hotel.name = ‘park’;
hotel[‘name’] = ‘park‘;
What are arrays used for?
Store a list of values and items