JavaScript Flashcards
What data type is returned by an arithmetic operation?
number
What is string concatenation?
Strings are combined using the addition operator
What purpose(s) does the + plus operator serve in JavaScript?
It either adds numbers together or concatenates strings
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
Takes the variable and either adds a number or concatenates a string to itself
What are objects used for?
They are used to store a group of variables
What are object properties?
The individual variables stored in an object
Describe object literal notation.
Declare a variable, use opening curly brace, then list each property (name: value,) then close with a curly brace
How do you remove a property from an object?
Use the delete keyword (delete object.propertyname)
What are the two ways to get or update the value of a property?
dot notation (object.newproperty) or bracket notation (object[‘newproperty’]) - dot notation is preferred
How are arrays different from “plain” objects?
- Arrays have order.
- Arrays have methods to remove items and the array will adapt/update for any changes made
- They are simply listed, they don’t have an additional value or label assigned to them and they operate differently
What number represents the first index of an array?
0
What is the length property of an array?
Tells you how many items there are in an array
How do you calculate the last index of an array?
Length - 1
Describe the parts of a function definition.
Function keyword, function name (optional), parameters separated by commas and surrounded by parentheses, code block, return statement (optional)
Describe the parts of a function call
Function name, arguments
When comparing them side-by-side, what are the differences between a function call and a function definition?
The function definition has parameters and a code block which set everything up, whereas the call simply plugs arguments into the parameters
What is the difference between a parameter and an argument?
Parameter is a placeholder, whereas an argument is what’s plugged into that placeholder
Why are function parameters useful?
- Allows for more concise code, since they only have to be written once
- Allows for different results for each function
What two effects does a return statement have on the behavior of a function?
- Ends the function
- Returns the value of the function
Why do we log things to the console?
To check that everything is working properly and to keep track of output
What is a method?
A method is a function that is a property of an object
How is a method different from any other function?
- Attached to an object, whereas functions a free-floating
- Can access data within objects
How do you remove the last element from an array?
Pop method