JavaScript Flashcards
What is the purpose of variables?
used to store data
How do you declare a variable?
using variable keyword
How do you initialize (assign a value to) a variable?
using variable keyword, variable name, assignment operator, and value
What characters are allowed in variable names?
can contain letters, digits, underscores, $
What does it mean to say that variable names are “case sensitive”?
This means that language keywords, variables, function names, and any other identifiers must always be typed with a consistent capitalization of letters (camelCase)
What is the purpose of a string?
datatype consists of
letters and other characters; store text data
What is the purpose of a number?
store numeric data
What is the purpose of a boolean?
used to create true/false statements.
What does the = operator mean in JavaScript?
assignment operator
How do you update the value of a variable?
reassignment; the var keyword would no longer be in the statement
What is the difference between null and undefined?
an undefined variable has been declared but not defined yet. null is an assigned value of nothing
Give five examples of JavaScript primitives.
number, strings, booleans, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
adding strings together
What purpose(s) does the + plus operator serve in JavaScript?
adds one value to another or concatenates strings
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
Addition assignment
What are objects used for?
group together related data to create a model
What are object properties?
unique named keys paired to values
Describe object literal notation.
made up of object name followed by key and value pairs wrapped in curly braces
How do you remove a property from an object?
delete object.property
What are the two ways to get or update the value of a property?
using dot notation or square brackets
What are arrays used for?
store a list of values
Describe array literal notation.
array name followed by the assignment operator then square brackets with values separated by commas
How are arrays different from “plain” objects?
arrays have order and methods for updating the array
What number represents the first index of an array?
0
What is the length property of an array?
results in the number of items in an array
How do you calculate the last index of an array?
array.length - 1
What is a function in JavaScript?
block of code designed to perform a particular task
Describe the parts of a function definition.
begins with a function keyword, followed by a name (optional), then parameters in parentheses, then open curly brace to start code block, optional return statement, ends with closing curly brace
Describe the parts of a function call.
function name followed by parentheses
When comparing them side-by-side, what are the differences between a function call and a function definition?
function definition begins with the function keyword, contains curly braces, and an optional return statement. function call only has function name and arguments inside parentheses.
What is the difference between a parameter and an argument?
parameters serve as a placeholder in the function definition and arguments are passed when a function is called
Why are function parameters useful?
the parameter will be holding the value of the argument when the function’s code block is run
What two effects does a return statement have on the behavior of a function?
causes the function to produce a value and it exits the function code block
What is a method?
a function which is a property of an object
How is a method different from any other function?
methods are attached to objects
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()
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?
strings are immutable and check with console.log() or documentation
Is the return value of a function or method useful in every situation?
no