JAVASCRIPT Flashcards
What is the purpose of variables?
to have data and store it to possibly use it later
make a piece of code mostly permanent
How do you declare a variable?
Using keywords such as “var, let, const”
How do you initialize (assign a value to) a variable?
using an equal sign (=)
What characters are allowed in variable names?
letters, numbers, dollar sign, or underscore (_)
cannot start a variable with a number
What does it mean to say that variable names are “case sensitive”?
case does not equal Case
What is the purpose of a string?
store text information
What is the purpose of a number?
numbers are for math
What is the purpose of a boolean?
to test for conditionals - only use the variable TRUE or FALSE
allows us to make a decision
without booleans –> you don’t get to do another way of branching others
What does the = operator mean in JavaScript?
assigning a value to a variable
How do you update the value of a variable?
assigning a new value on the same variable on a different line as long as the keyword, var was used because const cannot be changed because its constant
Don’t need another var on the next line. Just need to do variable = value
What is the difference between null and undefined?
Null –> indicator that it’s empty but plan to place something there –> purposeful emptiness –> declared by a developed –> needs to assign to a variable
undefined –> accidental emptiness –> declared by javascript language –> NEVER use this
Why is it a good habit to include “labels” when you log values to the browser console?
To ensure clarity and know what the value is assigned to. trying not to mistake that this value is not coming from another place.
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?
Putting two or more strings together to form a phrase or a sentence
What purpose(s) does the + plus operator serve in JavaScript?
addition or concatenation
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
allows a number or string to add to the variable to the right and produces a single value
What are objects used for?
to group multiple variables and functions to describe something
to create a box that holds multiple variables that is related to each other
What are object properties?
individual property data within a data
Describe object literal notation.
has property:value pairs with a comma separating it
How do you remove a property from an object?
delete operator object.property
What are the two ways to get or update the value of a property?
dot notation or square bracket notation
object.property OR object[‘property’]
What are arrays used for?
to store any list of information – > order may be extremely important or may not be
Describe array literal notation.
keyword with a variable equal to a square bracket and the list is separated by a comma
How are arrays different from “plain” objects?
arrays –> all the same datatype & length property is present
objects –> different datatype, bunch of different things
What number represents the first index of an array?
0
What is the length property of an array?
it calculates how many values they are in an array
How do you calculate the last index of an array?
variable.length - 1
What is a function in JavaScript?
process or set of actions that can be repeated within your code
Describe the parts of a function definition.
There is a function keyword, name of the function, parameter list with parentheses, curly brace, code that is running, return function
Describe the parts of a function call.
function name, parentheses, arguments
When comparing them side-by-side, what are the differences between a function call and a function definition?
Function call –> function keyword is not present for function call
function definition –> includes the code block + function keyword
What is the difference between a parameter and an argument?
parameter –> placeholder –> prepared to fulfill later
argument –> actual thing to call the function to execute
Why are function parameters useful?
it allows us to have variants depending on how we run the code. You could get different results with new values.
What two effects does a return statement have on the behavior of a function?
stops the functions
giveback a value
Why do we log things to the console?
for debugging, verification to check for data is working
What is a method?
function stored as an object
How is a method different from any other function?
method has a dot and a thing you’re calling it from (variable)
How do you remove the last element from an array?
.pop()
How do you round a number down to the nearest integer?
Math.floor() –> it’s always going down
How do you generate a random number?
Math.random()
How do you delete an element from an array?
.splice()