JavsScript Flashcards
What is the purpose of variables?
-Store data for a script to do its job
How do you declare a variable?
-var
How do you initialize (assign a value to) a variable?
-By using the assignment operator
What characters are allowed in variable names?
-Letters, numbers, dollar signs, underscore
What does it mean to say that variable names are “case sensitive”?
-Score and score are different variable names
What is the purpose of a string?
-String type data consists of letters and other characters
What is the purpose of a number?
-Numeric data type handle number quantities
What is the purpose of a boolean?
-Boolean data types can have one of two values: true or false.
What does the = operator mean in JavaScript?
-Assign a value to the variable
How do you update the value of a variable?
-By using the assignment operator
What is the difference between null and undefined?
-null is an intentionally assigned value to a nonexistent or invalid object, undefined means a variable has been declared but not defined yet
Why is it a good habit to include “labels” when you log values to the browser console?
-A console log “label” is simply a short string that describes the variable or value being logged
Give five examples of JavaScript primitives.
-There are 7 primitive data types: string, number, bigint, boolean, undefined, symbol, and null
What data type is returned by an arithmetic operation?
-Single numerical value
What is string concatenation?
-Concatenate is a fancy programming word that means “join together”
What purpose(s) does the + plus operator serve in JavaScript?
-The addition operator produces the sum of numeric operands or string concatenation
What data type is returned by comparing two values (, ===, etc)?
-Boolean
What does the += “plus-equals” operator do?
-The addition assignment operator adds the value of the right operand to a variable and assigns the result to the variable.
What are objects used for?
-Objects group together a set of variables and functions
What are object properties?
-Variables that are part of an object
Describe object literal notation.
- Object is the curly braces and their contents
- Separate each key from its value using a colon
- Separate each property and method with a comma (not after the last value)
How do you remove a property from an object?
- delete object.property
- delete object[‘property’]
What are the two ways to get or update the value of a property?
-dot notation or square bracket syntax
What are arrays used for?
-Storing lists of values that are related to each other
Describe array literal notation.
- Values are assigned to the array inside a pair of square brackets
- Each value is separated by a comma
How are arrays different from “plain” objects?
-Arrays create and store lists of data in a single variable while objects represent a variable with properties
What number represents the first index of an array?
0
What is the length property of an array?
-Holds the number of items in the array
How do you calculate the last index of an array?
-Subtract 1 from the value of the length property of an array
What is a function in JavaScript?
-Series of statements grouped together to perform a specific task
Describe the parts of a function definition.
- function keyword
- Name for the function
- Comma-separated list of zero or more parameters surrounded by ()
- Start of code block indicated by {
- Optional return statement
- End of code block indicated by }
Describe the parts of a function call.
- Function name
- Comma-separated list of zero or more arguments surrounded by()
When comparing them side-by-side, what are the differences between a function call and a function definition?
- Function definitions require function keywords and function callings do not require function keywords
- Function definitions have parameters and function callings have arguments
What is the difference between a parameter and an argument?
- Function parameters are the names listed in the function’s definition
- Function arguments are the real values passed to the function
Why are function parameters useful?
-The parameter will be holding the value of the argument
What two effects does a return statement have on the behavior of a function?
- Causes the function to produce a value we can use in our program
- Prevents any more code in the function’s code block from being run
Why do we log things to the console?
-For debugging and an easy way to inspect your variables in the browser
What is a method?
-A method is a function that is a property of an object
How is a method different from any other function?
-Method is associated with an object while a function is not
How do you remove the last element from an array?
-Calling the pop() method of the array
How do you round a number down to the nearest integer?
-Calling the floor() method of the Math object
How do you generate a random number?
-Calling the random() method of the Math object
How do you delete an element from an array?
-Calling the pop() method of the array
How do you append an element to an array?
-Calling the push() method of the array
How do you break a string up into an array?
-Calling the split() method of the variable
Do string methods change the original string? How would you check if you weren’t sure?
- It does not
- Log the variable containing the original string to the console
Roughly how many string methods are there according to the MDN Web docs?
-A lot
Is the return value of a function or method useful in every situation?
-No because some functions don’t return any value
Roughly how many array methods are there according to the MDN Web docs?
-A lot
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.
-==, !=, ===, !==, >, =, <=
What data type do comparison expressions evaluate to?
-Boolean
What is the purpose of an if statement?
- If statement evalutates a condition
- If condition evaluates to true, code block is executed
Is else required in order to use an if statement?
-Not required
Describe the syntax (structure) of an if statement.
- if keyword
- Condition between parenthesis
- Code block between curly braces