JavaScript Flashcards
What is the purpose of variables?
To store data that needs to be referenced later
How do you declare a variable?
Using the keyword var (const and let)
How do you initialize (assign a value to) a variable?
var variableName = value;
What characters are allowed in variable names?
Letters, numbers, $, _ (numbers cannot be first)
What does it mean to say that variable names are “case sensitive”?
They are sensitive to uppercase and lowercase letters
What is the purpose of a string?
Store a series of character, text content
What is the purpose of a number?
To store a numeric value, counting, measurement, math
What is the purpose of a boolean?
A data type that only has two possible values, to make decisions
What does the = operator mean in JavaScript?
Assigning a value to something
How do you update the value of a variable?
variableName = newValue
What is the difference between null and undefined?
Null: empty value, must be assigned by you, it represents something that does not have a value assigned to it yet,
Undefined: empty value, assigned by JavaScript
Where is var scoped
Var is scoped to the function that it is inside of. If you leave out the var keyword when using a variable in a function, JavaScript will look for the next variable that is scoped closest
Why is it a good habit to include “labels” when you log values to the browser console?
So you know what is being logged to the console
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?
Combining a string with another value and makes the result of that expression into a new string
What purpose(s) does the + plus operator serve in JavaScript?
Adding numbers, concatenating strings
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
Adds the value of the variable on the right to the variable on left, then assigns the result of that expression to the variable on the left
What are objects used for?
Storing data in a group or collection that makes sense
What are object properties?
Pieces of data stored within an object
Describe object literal notation.
Var variableName = {};
How do you remove a property from an object?
The delete operator: delete object.property
What are the two ways to get or update the value of a property?
Dot notation: object.propertyName
Bracket notation: object[‘propertyName’]
What are arrays used for?
To list data in a specific order
Describe array literal notation.
Var variableName = [];
How are arrays different from “plain” objects?
They are numerically indexed
What number represents the first index of an array?
0
What is the length property of an array?
How many elements are in the array
How do you calculate the last index of an array?
Array.length - 1
What is a function in JavaScript?
A special type of object that can be called, a set of reusable code
Describe the parts of a function definition.
Function functionName(parameter) {code block; return statement} Name and return statement are optional
Describe the parts of a function call.
functionName(argument) argument is optional
When comparing them side-by-side, what are the differences between a function call and a function definition?
A call will have arguments, a definition includes a code block
What is the difference between a parameter and an argument?
A parameter is a variable related to a function definition, an argument is a value related to a function call
Parameter is a placeholder for a variable that will eventually be passed into the function. It is included in the function definition
Argument is the actual variable that is passed into the function when it is called
Why are function parameters useful?
To pass additional information into a function for the function to use. It allows us to create more generalized, reusable functions
What two effects does a return statement have on the behavior of a function?
Causes the function to produce a value, ends the function
Why do we log things to the console?
To test and inspect your code and make sure your functions or methods are returning what you expect, or see what the values of variables are.
What is a method?
A property of an object that is a function