JavaScript Flashcards
What is the purpose of variables?
stores values and updates values, also gives value permanence (don’t have to keep declaring variable value)
How do you declare a variable?
var varname;
How do you initialize (assign a value to) a variable?
assignment operator (=)
What characters are allowed in variable names?
can start with: $, _, letters
can contain: $, _, letter, numbers
What does it mean to say that variable names are “case sensitive”?
javascript distinguishes between lower and upper cased letters
What is the purpose of a string?
pass around characters not to be interpreted as code (text content)
What is the purpose of a number?
math
What is the purpose of a boolean?
store true/false values, used for decision making (this or that)
What does the = operator mean in JavaScript?
putting a value into something
How do you update the value of a variable?
reassign variable value
variablename = newvalue
What is the difference between null and undefined?
both return/represent nothing/emptiness,
null: intentional nothingness (null is an assigned value), typically temporary space holder to be filled later
undefined typically unused by developers - usually a return from the console signifying the value has been deleted or was not assigned a value
Why is it a good habit to include “labels” when you log values to the browser console?
gives a point of reference
Give five examples of JavaScript primitives.
string, number, boolean, undefined, null
What data type is returned by an arithmetic operation?
number
What is string concatenation?
adds strings/numbers together to one larger string
What purpose(s) does the + plus operator serve in JavaScript?
arithmetic operation and string concatenation
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds the value and assigns the sum to the variable
What are objects used for?
area to store related properties
What are object properties?
variables within objects (/associated with objects)
Describe object literal notation.
curly braces + properties and values + object name
How do you remove a property from an object?
delete operator
What are the two ways to get or update the value of a property?
dot or bracket notation
object.property
object[‘property’]
bracket notation allows the text within to be interpreted by javascript (eg you can use variable names)
What are arrays used for?
ordered lists
Describe array literal notation.
square brackets [ ] with a comma between each item
How are arrays different from “plain” objects?
arrays are ordered, items are indexed (basically an object w keywords as consecutive numbers), arrays will repair themselves if items are deleted, arrays have a set length
What number represents the first index of an array?
0
What is the length property of an array?
calculate/count and stores the number of items in the array
How do you calculate the last index of an array?
subtract length by one
What is a function in JavaScript?
a repeatable series of statements to accomplish an operation
Describe the parts of a function definition.
function keyword
function name
parameters
code block
Describe the parts of a function call.
function name
parentheses
arguments if required
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call is much shorter since it doesn't have to define the function in curly braces function calls contain arguments in ' ' while definitions contain parameters
What is the difference between a parameter and an argument?
parameters are placeholders for arguments (which are real data)
What two effects does a return statement have on the behavior of a function?
allows us to assigns the result of the function
What two effects does a return statement have on the behavior of a function?
allows us to assigns the result of the function and ends the function
Why do we log things to the console?
keep track of js and verify output
What is a method?
function that is a property of an object
How is a method different from any other function?
methods are called using a dot notation bc they are a property of an object
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 of the Math object
How do you generate a random number?
random method of the Math object
How do you delete an element from an array?
splice method to remove at an arbitrary point, pop to remove at the end, shift to remove at the beginning
How do you append an element to an array?
push method
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 strings are immutable, console log the original string variable or look it up on mdn
Roughly how many string methods are there according to the MDN Web docs?
a lot (~30)