JS Flashcards
How do you declare a variable?
var, let, or const then name
How do you initialize (assign a value to) a variable?
equal ( = ) sign
What characters are allowed in variable names?
letters, numbers, symbols
What does it mean to say that variable names are “case sensitive”?
“name” is different from “Name”
What is the purpose of a string?
text content
What is the purpose of a number?
math stuff
What is the purpose of a boolean?
determine true or false
What does the = operator mean in JavaScript?
is assigned to
How do you update the value of a variable?
variable name = ‘new value’
What is the difference between null and undefined?
null - placed there on purpose, doesn’t exist
undefined - there’s nothing assigned to a variable
Why is it a good habit to include “labels” when you log values to the browser console?
to keep track of what the logs are for
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
putting two strings together
What purpose(s) does the + plus operator serve in JavaScript?
addition or concatenating strings
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adding something to the variable, then updating that variable
What does the += “plus-equals” operator do?
adding something to the variable, then updating that variable
What are objects used for?
key, value lists
What are object properties?
variables specifically for objects
Describe object literal notation.
variable name, the curly-braces surrounding key-value pairs, separated by commas
How do you remove a property from an object?
delete operator then obj.key
What are the two ways to get or update the value of a property?
dot notation, or bracket notation
What are arrays used for?
lists
Describe array literal notation.
variable name, square bracket, then values separated by commas
How are arrays different from “plain” objects?
arrays’ keys are their index numbers
What number represents the first index of an array?
0
What is the length property of an array?
get how many items are in the array
How do you calculate the last index of an array?
array.length - 1
What is a function in JavaScript?
a set of statements that performs a task
Describe the parts of a function definition.
function keyword, optional function name, optional parameters (separated by a comma), function body, optional return statement
Describe the parts of a function call.
function name with parenthesis with optional arguments
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call - function name and parenthesis (optional arguments) function definition - has all the jazz, tells the computer what to do
What is the difference between a parameter and an argument?
parameter - used in function definition
argument - used in function call
Why are function parameters useful?
can use keyword for a different things, instead of specifying the item again and again
What two effects does a return statement have on the behavior of a function?
- function produces a value that can be used
2. prevents more code in the block from running
Why do we log things to the console?
to inform developers what the code is doing
What is a method?
a function in an object
How is a method different from any other function?
it’s specifically attached to an object
How do you remove the last element from an array?
.pop()
How do you round a number down to the nearest integer?
Math.floor()
How do you generate a random number?
Math.random()
How do you delete an element from an array?
.splice(startIndex, # of items to remove)
How do you append an element to an array?
.push()
How do you break a string up into an array?
.split()
Do string methods change the original string? How would you check if you weren’t sure?
no, strings are immutable
use console.log(string) to check
Roughly how many string methods are there according to the MDN Web docs?
30+
Is the return value of a function or method useful in every situation?
no
Roughly how many array methods are there according to the MDN Web docs?
38+
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
Give 6 examples of comparison operators.
===, !==, less than, greater than, less than or equal to, greater than or equal to
What data type do comparison expressions evaluate to?
boolean