Javascript Flashcards
What is the purpose of variables?
To store values within them
How do you declare a variable?
var, let or const followed by variable name
How do you initialize (assign a value to) a variable?
Assignment operator =
What characters are allowed in variable names?
Letters, numbers, underscore, $
What does it mean to say that variable names are “case sensitive”?
Calling on the variable will require matching the case of all letters exactly
What is the purpose of a string?
Represents letters
What is the purpose of a number?
Represents numerical values
What is the purpose of a boolean?
Represents true or false, 1 or 0
What does the = operator mean in JavaScript?
Assignment operator
How do you update the value of a variable?
variable = new value
What is the difference between null and undefined?
Null means there is no value whereas undefined means the value is not declared yet
Why is it a good habit to include “labels” when you log values to the browser console?
To see what you are logging
Give five examples of JavaScript primitives.
number, string, boolean, null, undefined
What data type is returned by an arithmetic operation?
Number
What is string concatenation?
Combining multiple string inputs
What purpose(s) does the + plus operator serve in JavaScript?
To concatenate strings or to add numbers
What data type is returned by comparing two values (<, >, ===, etc)?
Boolean values
What does the += “plus-equals” operator do?
Add and assign
What are objects used for?
To group variables and functions
What are object properties?
Keys and values
Describe object literal notation.
Declare variable = {key: value, key: value}
How do you remove a property from an object?
delete object.key
What are the two ways to get or update the value of a property?
Dot or bracket notation, pair with assignment operator if updating
What are arrays used for?
To have a list of items
Describe array literal notation.
array name = [item, item, item];
How are arrays different from “plain” objects?
Uses brackets rather than curly braces, and indexes rather than keys
What number represents the first index of an array?
0
What is the length property of an array?
array.length
Returns total length of the array or total number of items within the list
How do you calculate the last index of an array?
array.length - 1
What is a function in JavaScript?
A block of code that can be called on and executed
Describe the parts of a function definition.
function declaration, name, parameters, function code block
Describe the parts of a function call.
function name (argument)
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function definition will have “function” prior to the function name. Function call may include arguments whereas definition would have parameters
What is the difference between a parameter and an argument?
Parameters are placeholders whereas arguments are the actual data we want to use
Why are function parameters useful?
They act as placeholders that can be referenced within the function code block
What two effects does a return statement have on the behavior of a function?
Produces a value, exits the function
Why do we log things to the console?
To check our results
What is a method?
A function that is a property of an object
How is a method different from any other function?
It is property of an object. Functions don’t have a dynamic “this” binding
How do you remove the last element from an array?
.pop() method
How do you round a number down to the nearest integer?
.floor() method
How do you generate a random number?
Math.random() method
How do you delete an element from an array?
.pop(), .shift(), .splice()
How do you append an element to an array?
.push(), .unshift()
How do you break a string up into an array?
.split() method
Do string methods change the original string? How would you check if you weren’t sure?
No they are not referenced data types. They are immutable. You can check using console.log()
Roughly how many string methods are there according to the MDN Web docs?
50
Is the return value of a function or method useful in every situation?
No, some returned values may be created to be used at a later time or we may just want it to execute an action without returning the results