JavaScript Flashcards
(255 cards)
What is the purpose of variables?
a container used to store data so that you can use it later
How do you declare a variable?
using let, const, or var keyword and then giving it a name in camelCase
How do you initialize (assign a value to) a variable?
using = e.g.(var x = 2)
What characters are allowed in variable names?
letters, numbers, $ sign, and underscore
What does it mean to say that variable names are “case sensitive”?
two variables can have the same name but different values if their first letter is capitalized and uncapitalized
What is the purpose of a string?
used to store and represent text information
What is the purpose of a number?
used to store and represent numerical values and do math
What is the purpose of a boolean?
used for conditional statements since booleans can only return two values, either true or false. Helps the program make a decision.
What does the = operator mean in JavaScript?
assignment, usually when assigning a value to a variable
How do you update the value of a variable?
using the assignment operator again, don’t need to use a var keyword the second time
What is the difference between null and undefined?
null is purposeful emptiness, undefined is not purposeful emptiness. Null is declared by the developer, whereas undefined is declared by the computer.
Why is it a good habit to include “labels” when you log values to the browser console?
to make it clearer what you’re logging exactly in that line of code
Give five examples of JavaScript primitives.
string, number, boolean, null, and undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
to join two or more strings together
What purpose(s) does the + plus operator serve in JavaScript?
add numbers or concatenate strings
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
takes the variable and add something to it and then reassigns that value to the same variable.
Are strings immutable? and what does that mean?
yes - you cannot change the content of a string once it’s been created. like changing the middle letter of “cat” from a to o. it will always be a.
What are objects used for?
used to store multiple pieces of information that are related to eachother
What are object properties?
individual piece of named data within an object
Describe object literal notation.
declare object with name, assignment operator, opening curly braces for object then key value pairs separated by a comma, then closing curly braces.
How do you remove a property from an object?
delete operator
What are the two ways to get or update the value of a property?
dot notation e.g - obect.text or bracket notation - e.g. object[‘property’] = new value