JS 1 Flashcards
What is the purpose of variables?
variables are assigned data, and allow for referring to them later to access that data
How do you declare a variable?
“var” or “let” keyword followed by the name
How do you initialize (assign a value to) a variable?
variable name, equal sign, followed by value assigned
What characters are allowed in variable names?
numbers, letters, _, $
What does it mean to say that variable names are “case sensitive”?
case (lowercase/uppercase) needs to be exact, since they are differentiated in javascript
What is the purpose of a string?
a string is made up of characters in a row and is used to store text
What is the purpose of a number?
a number is for numeric value and used in mathematical operations
What is the purpose of a boolean?
booleans allow for the ability to make decisions based on true or false
What does the = operator mean in JavaScript?
the assignment operator allows for assigning a value to a variable
How do you update the value of a variable?
variable name, then equal sign, followed by new value
What is the difference between null and undefined?
- null is assigned to a variable which should be purposefully empty for now
- undefined is accidentally empty, assigned by computer when no value is provided
Why is it a good habit to include “labels” when you log values to the browser console?
helps to know where the information is coming from, helps other developers
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?
combining strings with the plus operator
What purpose(s) does the + plus operator serve in JavaScript?
adding numbers or combining strings (concatenation)
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds the result of the right side plus the left side and replaces the left side
What are objects used for?
store key/value collections of data, as well as methods relevant to that object
What are object properties?
the association between a key and a value, or the equivalent of a variable stored in an object
Describe object literal notation.
a way to initialize an object using the left curly brace and right curly brace, with optional properties nested inside
How do you remove a property from an object?
- use the delete operator to remove the property completely
- assign to empty string to remove the value only
What are the two ways to get or update the value of a property?
- dot notation: object name, dot, property key
- bracket notation: object name, brackets enclosing quotation marks enclosing property key
What are arrays used for?
arrays store lists of information
Describe array literal notation.
square brackets surrounding the data strings
How are arrays different from “plain” objects?
arrays are ordered by number, objects have property names
What number represents the first index of an array?
zero
What is the length property of an array?
number of elements in an array
How do you calculate the last index of an array?
array.length - 1
What is a function in JavaScript?
a reusable container of code which performs actions
Describe the parts of a function definition.
function keyword, function name, parameters surrounded by parenthesis, code block, optional return statement
Describe the parts of a function call.
function name, arguments surrounded by parenthesis
When comparing them side-by-side, what are the differences between a function call and a function definition?
A function definition is the creation/declaration of the function with a function keyword and code block, while a function call is running/invoking an already created function.
What is the difference between a parameter and an argument?
A parameter takes in arguments. Parameters are placeholders in a function’s definition, while arguments are values used in a function’s call.
Why are function parameters useful?
Parameters allow for performing actions on different data of the same type when the function is invoked multiple times.
What two effects does a return statement have on the behavior of a function?
a return statement exits the code block and allows the called function to evaluate to the returned value
Why do we log things to the console?
to see an output to help debugging in development
What is a method?
a function in an object
How is a method different from any other function?
a method is specific to an object, so have to specify object name with method
How do you remove the last element from an array?
.pop() method
How do you round a number down to the nearest integer?
Math.floor() method
How do you generate a random number?
Math.random() method
How do you delete an element from an array?
.splice() method with first arg being index and second arg being number of items to remove
How do you append an element to an array?
.push() method
How do you break a string up into an array?
.split() method with argument being what character(s) you want to split with
Do string methods change the original string? How would you check if you weren’t sure?
No, MDN documentation
Is the return value of a function or method useful in every situation?
not always
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 operator. > Greater than operator. <= Less than or equal operator. >= Greater than or equal operator. !== strict inequality operator === strict equality operator
What data type do comparison expressions evaluate?
boolean
What is the purpose of an if statement?
check a condition to make choices
Is ‘else’ required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if keyword, then condition in parenthesis, then body in curly braces
What are the three logical operators?
&& and operator
|| or operator
! not operator
How do you compare two different expressions in the same condition?
use logical operators (&&, ||) in between the expressions
What is the purpose of a loop?
repetition
What is the purpose of a condition expression in a loop?
to see if the loop should stop
What does “iteration” mean in the context of loops?
an instance of repeating the code block
When does the condition expression of a while loop get evaluated?
before the while loop body runs
When does the initialization expression of a for loop get evaluated?
first
When does the condition expression of a for loop get evaluated?
after initialization, but before code block runs
When does the final expression of a for loop get evaluated?
at the end of each iteration
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
break keyword
What does the ++ increment operator do?
increases value of operand by 1
How do you iterate through the keys of an object?
for / in loop