JavaScript Flashcards
What is the purpose of variables?
Data storage for scripts to call back to
How do you declare a variable?
They are declared with
- var
- let
- const
How do you initialize (**assign a value to) a variable?
Variables are initialized by including the assignment operator ‘=’
example: var example = true
What characters are allowed in variable names?
- letters
- numbers (CANNOT be the first character of a variable name)
- underscores(_)
- dollar signs
What does it mean to say that variable names are “case sensitive”?
Variables names must follow the same casing when used later in a script, so the variables “fullName” and “FullName” would be detected as two different variables
What is the purpose of a string?
To store text (a sequence of characters)
What is the purpose of a number?
To store a piece of numerical data (for math/calculations)
What is the purpose of a boolean?
To store a state of something is or is not
What does the = operator mean in JavaScript?
This is the assignment operator, it initializes variables and can re-assign their values.
How do you update the value of a variable?
Re-assign it with the assignment operator
What is the difference between null and undefined?
Null
is a value explicitly assigned to not existUndefined
is a default value set to variables that have not been assigned
Give five examples of JavaScript primitives.
- Number
- Boolean
- String
- Undefined
- Null
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
The adding of a string to the end of another string
The result is always a string.
What purpose(s) does the + plus operator serve in JavaScript?
It tells values to combine by either concatenating or adding
What data type is returned by comparing two values (<, >, ===, etc)?
Boolean (true/false)
What does the += “plus-equals” operator do?
Addition assignment operator: adds the value of the right operand to a variable and assigns the result to the variable. Can be used to add or concatenate.
What are objects used for?
They are used to group related variables and functions
What are object properties?
Related variables/functions stored in an object become a property/method of the object
Describe object literal notation.
list out the properties and methods within curly braces and assign it to a variable
{ hasProperty: true, name: 'example', };
What are the two ways to get or update the value of a property?
Dot notation and bracket notationexampleObject.name'
-dot notationexampleObject['name']
-bracket notation
What are arrays used for?
They are used to store lists of data where the order is important or unimportant
Note: Unlike objects the key that the variables are paired to are numbers as they are indexed.
Describe array literal notation.
A list contained in two square-brackets ([ ]) with each value separated with commas
How are arrays different from “plain” objects?
The key that the variables are paired to are numbers and not properties. They are accessed with bracket-notation unless using a method.
(ex.)console.log(exampleArray[0])