JavaScript Flashcards
What are objects used for?
Objects allow us to put data that makes sense together in one group/container.
What are object properties?
Data stored in an object.
Describe object literal notation.
var objectName = {
property: value,
otherProperty: otherValue
}
How do you remove a property from an object?
Using the delete operator.
delete object.propertyName
What are the two ways to get or update the value of a property?
Dot Notation:
object.propertyName = “new value”
Bracket Notation:
object[‘properyName’] = “new value”
What is the purpose of variables?
Variables allow us to store data in memory to use later.
How do you declare a variable?
var variableName;
How do you initialize (assign a value to) a variable?
var variableName = value;
What characters are allowed in variable names?
letters, numbers (non-starting), $, _
What does it mean to say that variable names are “case sensitive”?
When calling a variable, it must be exactly the name of that variable with exact casing.
variable and Variable are different variables.
What is the purpose of a string?
What is the purpose of a number?
What is the purpose of a boolean?
Strings store text data
Numbers store numbers, used for measurements, etc.
Booleans store true or false, used for yes and no situations
What does the = operator mean in JavaScript?
Assignment
How do you update the value of a variable?
varName = updatedValue;
What is the difference between null and undefined?
Null is a value for purposely blank, undefined means a variable has not been assigned a value
Why is it a good habit to include “labels” when you log values to the browser console?
Labels give us context to what is being logged.
What data type is returned by an arithmetic operation?
number
What is string concatenation?
The joining of strings
What purpose(s) does the + plus operator serve in JavaScript?
Addition, concatenation of strings
What data type is returned by comparing two values (, ===, etc)?
Boolean, with values true or false
What does the += “plus-equals” operator do?
Adds the right side value to the left side variable and reassigns that new value to the left side variable
What are arrays used for?
Arrays are used for storing lists of similar data.
Describe array literal notation.
[firstItem, secondItem]
How are arrays different from “plain” objects?
Arrays have order, item keys are indices.
What number represents the first index of an array?
0, arrays are 0 indexed
What is the length property of an array?
The length property is the number of items in the array
How do you calculate the last index of an array?
length-1
Why are function parameters useful?
Allows us to pass data in dynamically
What two effects does a return statement have on the behavior of a function?
1) Cause the function to produce a value
2) Exits the function, code in the code black after will not run
What is a function in JavaScript?
A callable object that contains reusable code
Describe the parts of a function definition.
- function keyword
- name
- (parameters)
- { code block
}
Describe the parts of a function call.
functionName(arguments);
When comparing them side-by-side, what are the differences between a function call and a function definition?
The definition has function keyword, code block, and paramters compared to arguments in the function call which has no function keyword and no code block
What is the difference between a parameter and an argument?
Parameters are placeholders in the function definition.
Arguments are actual values passed into a function call.
Why do we log things to the console?
For inspection, testing and spotting errors in code
What is a method?
How is a method different from any other function?
A function that is a property of an object.
How do you remove the last element from an array?
With the pop() method
array.pop()
How do you round a number down to the nearest integer?
Math.floor()
How do you generate a random number?
Math.floor(Math.random( ) * (end - start) + 1 ) + start
(end-start) - gives range
+1 - because Math.random( ) is 1 (non-inclusive)
How do you delete an element from an array?
array.splice(start, deleteCount)
Do string methods change the original string? How would you check if you weren’t sure?
No, strings are immutable
Alter a string, then console.log the original string
Is the return value of a function or method useful in every situation?
Not always, functions may just be used to change a variable but not have to return anything.
Give 6 examples of comparison operators.
> < >= <= == ===
What data type do comparison expressions evaluate to?
boolean, true or false