JavaScript Flashcards
What is the purpose of variables?
It allows the program to store values
How do you declare a variable?
Begin with the keyword var followed by the variable’s name
How do you initialize (assign a value to) a variable?
Use “=” to set the variable equal to the value
What characters are allowed in variable names?
Any letters, numbers, “$”, and “_”
What does it mean to say that variable names are “case sensitive”?
Casing changes the name of a variable
What is the purpose of a string?
To represent text values
What is the purpose of a number?
To represent numerical values used in calculation and indexing
What is the purpose of a boolean?
To represent logic values
What does the = operator mean in JavaScript?
It means to assign a value
How do you update the value of a variable?
Assign the variable with the new value
What is the difference between null and undefined?
Null is still considered an object while undefined is not
Why is it a good habit to include “labels” when you log values to the browser console?
It gives more clarity to the console, which is helpful for debugging
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?
When two or more strings are combined to make a new string that is a combination of the original strings
What purpose(s) does the + plus operator serve in JavaScript?
It is both the arithmetic operator for addition and the concatenation operator for strings
What data type is returned by comparing two values (> ,< , ===, etc)?
boolean
What does the += “plus-equals” operator do?
It applies the + operator to the values on either side of the += and assigns the result to the variable on the left
What are objects used for?
They group together variables and functions to create a model of a real-world entity
What are object properties?
An object’s variables; a key/value pair
Describe object literal notation.
You define the object in curly braces {}, separate properties with commas, and define key/value pairs using a colon to separate them
How do you remove a property from an object?
Use the keyword delete followed by the object
What are the two ways to get or update the value of a property?
Dot notation object.key or bracket notation object[‘key’]
What are arrays used for?
Arrays are used for listing items
Describe array literal notation.
Any number of values separated by commas, enclosed in square brackets
How are arrays different from “plain” objects?
The name of a property in the array is preset as a number
What number represents the first index of an array?
0
What is the length property of an array?
Gives the total number of objects in an array
How do you calculate the last index of an array?
array.length - 1
What is a function in JavaScript?
A portion of code that can be reused throughout a program
Describe the parts of a function definition.
the keyword “function”, the optional function name, the parameters, and the code block
Describe the parts of a function call.
There is the function name followed by the arguments within the parentheses
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function call does not have the function keyword or code block
What is the difference between a parameter and an argument?
A parameter is the the general input used when defining the function, while an argument is the specific input used when calling the function
Why are function parameters useful?
They allow the function to take in values that can be manipulated across various cases
What two effects does a return statement have on the behavior of a function?
It provides a value that the function evaluates to, and terminates the reading of the function code block
Why do we log things to the console?
To verify our code works and help debug our code
What is a method?
A function defined within an object
How is a method different from any other function?
They can only be called on the object they are defined in
How do you remove the last element from an array?
.pop()
How do you round a number down to the nearest integer?
Math.floor(number)
How do you generate a random number?
Math.random()
How do you delete an element from an array?
.splice(start, deleteCount, item1, item2, …)
How do you append an element to an array?
.push(element)
How do you break a string up into an array?
.split(separator)
Do string methods change the original string? How would you check if you weren’t sure?
They do not; this can be confirmed by console logging the original string
Roughly how many string methods are there according to the MDN Web docs?
~50
Is the return value of a function or method useful in every situation?
No, for example .push() will return the new length of the array
Roughly how many array methods are there according to the MDN Web docs?
~30
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 sign
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
To write code that only executes conditionally
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
keyword if, condition statement, code block
What are the three logical operators?
&&, ||, !
How do you compare two different expressions in the same condition?
Connect them with a logical operator
What is the purpose of a loop?
It allows us to repeat behavior