JavaScript Flashcards
What is the purpose of variables?
To store data or information or values.
How do you declare a variable?
Using the variable keywords such as: ‘var’, ‘let’, or ‘const’
How do you initialize (assign a value to) a variable?
by using the assignment operator =
What characters are allowed in variable names?
letters, numbers, $, _, capitol letters. Do not start with a number.
What does it mean to say that variable names are “case sensitive”?
upper case and lower case matters.
What is the purpose of a string?
to store text values
What is the purpose of a number?
to store numbers
What is the purpose of a boolean?
there are only 2 values, true or false
What does the = operator mean in JavaScript?
assigns a value to a variable
How do you update the value of a variable?
assign the variable a new value
What is the difference between null and undefined?
a null value represents a reference that points, generally intentionally, to a nonexistent or invalid object or address.
undefined is a primitive value automatically assigned to variables that have just been declared, or to formal arguments for which there are no actual arguments.
Why is it a good habit to include “labels” when you log values to the browser console?
it is much clearer which variables are being logged and in what order.
Give five examples of JavaScript primitives.
strings, numbers, booleans, undefined, null
What data type is returned by an arithmetic operation?
a number
What is string concatenation?
combining multiple strings into 1 string
What purpose(s) does the + plus operator serve in JavaScript?
to add numbers, or to concatenate strings
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds more to a variable then reassigns it. called addition assignment
What are objects used for?
Object group together variables and functions to create a model of something from the real world.
What are object properties?
variables inside an object
Describe object literal notation.
Name/key/property is separated from value by a colon.
Name/key/property-value pairs are separated by commas.
No comma follows the last name/key/property-value pair.
How do you remove a property from an object?
by using the delete keyword.
delete objectName.propertyName
What are the two ways to get or update the value of a property?
dot notation and bracket notation
What are arrays used for?
storing a list of values in a variable
Describe array literal notation.
var array = [item1, item2, item3, etc ]
How are arrays different from “plain” objects?
arrays have index numbers(starting at 0) instead of keys/property names.
What number represents the first index of an array?
0
What is the length property of an array?
.length returns how many things are in the array
How do you calculate the last index of an array?
array.length - 1
What is a function in JavaScript?
Functions are a special kind of object that is “callable”. The code inside the function runs when the function is “called”.
Describe the parts of a function definition.
the function keyword,
an optional name,
zero or more parameters,
a code block,
an optional return statement
Describe the parts of a function call.
The function’s name. A comma-separated list of zero or more arguments surrounded by () parentheses.
When comparing them side-by-side, what are the differences between a function call and a function definition?
The function definition contains the code.
Calling a function does NOT use the “function” keyword.
What is the difference between a parameter and an argument?
A parameter is like a placeholder. When we define a function, we declare parameters and that when we call a function, we pass it arguments.
Why are function parameters useful?
Parameters allow a function to perform tasks without knowing the specific input values ahead of time.
What two effects does a return statement have on the behavior of a function?
A return statement causes the function to produce a value.
A return statement also exits the function; no code after the return statement is executed.
Why do we log things to the console?
To check if our code is working as intended.
What is a method?
A method is a function which is a property of an object.
How is a method different from any other function?
methods are associated with objects.
How do you remove the last element from an array?
calling the pop() method.
array.pop()