JavaScript Flashcards
What is the purpose of variables?
It is to store bits of information to use later
How do you declare a variable?
You have to use a variable keyword like ‘var’ and then follow it with a variable name. From there, you use the assignment operator ‘=’ and assign a value to it
How do you initialize (assign a value to) a variable?
[variable name] = [variable value]
What characters are allowed in variable names?
The name must begin with a letter, dollar sign, or an underscore
Can contain letters, numbers, dollar signs, or underscores
What does it mean to say that variable names are “case sensitive”?
Score and Score would be different values
What is the purpose of a string?
Used for working with any kind of text
Frequently used for adding new content to a page
What is the purpose of a number?
Counting and calculating
What is the purpose of a boolean?
Serves as an on/off switch
Helpful in determining which part of the script should run
What does the = operator mean in JavaScript?
Assignment operator
Gives value to something
How do you update the value of a variable?
To update you would re-assign a value to the variable
What is the difference between null and undefined?
a null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address.
Every Object is derived from null value, and therefore typeof operator returns object for it:
undefined is a primitive value automatically assigned to variables that have just been declared, or to formal arguments for which there are no actual arguments.
Why is it a good habit to include “labels” when you log values to the browser console?
So that there is context to the output
Helps with debugging
Give five examples of JavaScript primitives.
data that is not an object and has no methods. There are 7 primitive data types: string, number,, boolean, undefined,, and null.
We can disregard bigInt and symbol for the time being
What data type is returned by an arithmetic operation?
number
What is string concatenation?
The process of joining together two or more strings to create one new string
What purpose(s) does the + plus operator serve in JavaScript?
To add or concatenate
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
It adds then re-assigns the variable
What are objects used for?
They are used for storing different variables and values of different data types
What are object properties?
A variable that is in an object.
Individual key in an object that correlates with a value
Describe object literal notation.
Create a variable and assign it to a value with curly braces. In the curly braces have names that indicate properties or methods and assign them value by using a colon
How do you remove a property from an object?
To delete a property, you use the keyword delete and then use the dot notation to identify the property or method you want to remove from the object
What are the two ways to get or update the value of a property?
Using dot notation or using square brackets
What are arrays used for?
When working with a list or a set of values related to each other
Especially helpful when you do not know how many items a list will contain
Representing lists of data