JS Flashcards
What is the purpose of variables?
Variables are used to store information that will be used later
How do you declare a variable?
We declare a variable by using the var keyword followed by the variable
name, then assignment operator followed by a value
How do you initialize (assign a value to) a variable?
We use variable name, followed by the assignment
operator (=) followed by a variable value
What characters are allowed in variable names?
letters, numbers, underscore, and dollar signs, but
variables can not begin with a number
What does it mean to say that variable names are ”case sensitive”?
It means uppercase and lowercase
letters has an affect on the word name. As an example, ”A” is different that ”a
What is the purpose of a string?
Used for tasks involving text content or tasks involving words or
phrases
What is the purpose of a number?
Used for tasks involving counting, adding, or mathematical operations,or anything that involves numbers
What is the purpose of a boolean?
Used for true/false tasks or used for decision making
What does the = operator mean in JavaScript?
= is an assignment operator. It sets a variable to
equal something or update a variable’s value
How do you update the value of a variable?
We will use the assignment operator for the variable
What is the difference between null and undefined?
null means the value is nonexistent where undefined
means the variable has not been defined or the variable has just been declared
Why is it a good habit to include ”labels” when you log values to the browser console?
So we can know what the outputs are referring to
Give five examples of JavaScript primitives
- string
- number
- boolean
- undefined
- null
- symbol
- bigint
2
What data type is returned by an arithmetic operation?
numbers
What is string concatenation?
It is combining two strings into one string
What purpose(s) does the + plus operator serve in JavaScript?
this is used for string concatenation
and addition
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += ”plus-equals” operator do?
this will add the number and then set the variable
equal to the result
What are objects used for?
Objects are a group of variables and functions used to create a model of
something from the real world
What are object properties?
Object properties are variables that are apart of an object
Describe object literal notation
Object literal notation is used to create an object. We start with a
var keyword followed by a variable name with the assignment operator and curly braces. Inside the
curly braces, we have a key and their value separated by a colon. Each key is separated by a comma
How do you remove a property from an object?
We would use the delete operator followed by the
object name, period, and the property we want to remove
What are the two ways to get or update the value of a property?
to access the value of a property, we would use object, period, followed by the property name (object.newValue).
To update the value of an object property, we would used, object, open bracket, property name, close
bracket, assignment operator, and the new property value. (object[’property’] = newValue)
What are arrays used for?
Arrays are used for storing data in an organized and predictable manner.
Each value is enumerated. Store a list of data in a set order
Describe array literal notation.
We start with a var keyword, followed by the array name, then
assignment operator, open bracket, values stored in the array in order, and close bracket. (var array
= [1,2,3])
How are arrays different from ”plain” objects?
Arrays differ from plain objects for arrays are ordered
where objects are not
What number represents the first index of an array?
0
What is the length property of an array?
It will give the number of items in an array
How do you calculate the last index of an array?
We will take the length of the array and subtract 1
What is a function in JavaScript?
Functions are a “chunk” of code that you can use over and over
again, rather than writing it out multiple times
Describe the parts of a function definition.
function keyword, function name (optional), open curly
brace, code, return statement, and close curly brace
Describe the parts of a function call.
a function call is when we are calling a function to run their block
of code with arguments. We need the function name, and the arguments
When comparing them side-by-side, what are the differences between a function call and a function
definition?
A function call will use specific arguments where a function definition with have a general
parameter. Also, there is no curly braces in a function call or function keyword
What is the difference between a parameter and an argument?
A parameter is used in a function
definition where argument is used in calling a function
Why are function parameters useful?
They are a placeholder for what kind of inputs the function will
take. They could give a clue into what the function wants as an argument and used for variance for
functions
What two effects does a return statement have on the behavior of a function?
The return statement causes the function to produce a value we can use in our program and Prevents any more code in the
function’s code block from being run
Why do we log things to the console?
So we can verify the outputs
What is a method?
A method is a function which is a property of an object
How is a method different from any other function?
It is because they are within an object
How do you remove the last element from an array?
We can use the pop() method of the array object
to remove the last element from an array
How do you round a number down to the nearest integer?
We can use the floor() method of the Math object
How do you generate a random number?
We can use the random() method of the Math object
How do you delete an element from an array?
We can use splice() method of the array object with a
start index followed by 1 item