JavaScript Flashcards
What is the purpose of variables?
The purpose of variables is to store a value.
How do you declare a variable?
A variable is declared with the const, var, or let keyword along with a name. e.g. ‘var test’.
How do you initialize (assign a value to) a variable?
To initialize a variable you use the = operator. e.g. ‘var test = ‘test’ ‘.
What characters are allowed in variable names?
The characters used must be a letter, underscore, or $.
What does it mean to say that variable names are “case sensitive”?
Variables are distinguished by their capitalization. e.g. ‘var Test’ and var test’ are different variables.
What is the purpose of a string?
A string is used to store a sequence of characters.
What is the purpose of a number?
A number is used to store numeric values.
What is the purpose of a boolean?
A boolean is used to store a true/false value.
What does the = operator mean in JavaScript?
The = operator is the assignment operator. It assign a value to a variable.
How do you update the value of a variable?
To update a variable you call the variable along with a new value. e.g. ‘test = ‘hi’.
What is the difference between null and undefined?
The Null type is purposely defined, while undefined is typically accidental.
Why is it a good habit to include “labels” when you log values to the browser console?
Adding labels to console log makes it easier to distinguish where the value is coming from.
Give five examples of JavaScript primitives.
The JavaScript primitives are: Number, String, Boolean, undefined, BigInt, and Symbol.
What data type is returned by an arithmetic operation?
Numeric data is returned by an arithmetic operation.
What is string concatenation?
String concatenation is joining strings by using the + operator. e.g. ‘var test = ‘hi ‘ + ‘name’ will return ‘hi name’.
What purpose(s) does the + plus operator serve in JavaScript?
The + operator is used for concatenation along with addition.
What data type is returned by comparing two values (, ===, etc)?
The data type returned by comparison operators is a boolean. e.g. true/false
What does the += “plus-equals” operator do?
The += operator adds both sides of an assignment together before assigning. e.g. var test = 1, var hello = 1 test += hello is now equal to '2'.
What are objects used for?
Objects are used to store multiple values.
What are object properties?
Object properties are the names of their values. e.g. ‘number: 2’.
Describe object literal notation.
A variable declaration followed by an object literal its containing properties, that are separated by commas, and a closing literal. e.g. var object = { property: ‘value’ }
How do you remove a property from an object?
To remove a property from an object the ‘delete’ operator would be used. e.g. ‘delete object.property’.
What are the two ways to get or update the value of a property?
To get/update a property you can use either bracket or dot notation. e.g. object.property or object[‘property’].
What are arrays used for?
Arrays are used to store multiple values.
Describe array literal notation.
A variable declaration followed by an array literal its containing properties, that are separated by commas, and a closing literal. e.g. var array = [ ‘value’ ]
How are arrays different from “plain” objects?
Arrays store multiple values without property names.
What number represents the first index of an array?
The first index of an array is [0]. The first value is stored in ‘0’ not ‘1’.
What is the length property of an array?
The length property is the number of values stored within the array.
How do you calculate the last index of an array?
To find the last index of an array you would use ‘array.length - 1’ as the index starts with 0 not 1.
What is a function in JavaScript?
A function is a code block designed for a certain task that can be repeatedly used with different inputs.
Describe the parts of a function definition.
A function definition consists of the function keyword followed by an optional name, a comma separated list of zero or more parameters surrounded by parentheses, the opening code block using ‘{‘, an optional return statement, and the ending block ‘}’.
Describe the parts of a function call.
A function call consists of the function’s name and arguments to input.
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function definition needs the function keyword and placeholder parameter names. A function call needs just the function name and the input rather than parameters.
What is the difference between a parameter and an argument?
A Parameter is a placeholder for a value. An argument is that said value.
Why are function parameters useful?
Parameters allow easy access to the inputted value via its name.
What two effects does a return statement have on the behavior of a function?
A return statement will exit the code block and not continue while also outputting a value.