JavaScript Flashcards
What is the purpose of variables?
To store data
How do you initialize (assign a value to) a variable?
Assign a value after the assignment operator
What characters are allowed in variable names?
letters, numbers, dollar sign $, or an underscore _
What does it mean to say that variable names are “case sensitive”?
For the variable to be recognized, it needs to be entered with the same casing as it was when it was declared
What is the purpose of a boolean?
To determine if something is true or false, and to tell if script should run or not in conditionals
What does the = operator mean in JavaScript?
It is the assignment operator
How do you update the value of a variable?
Reassigning it without declaring it again, you can leave off the Var
What is the difference between null and undefined?
Null is intentional whereas undefined hasn’t been assigned yet
Give five examples of JavaScript primitives.
string, number, bigint, boolean, undefined, symbol, and null.
What is string concatenation?
joining together two or more strings to make a single value
What purpose(s) does the + plus operator serve in JavaScript?
addition for strings (concatenation) and numbers
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
Addition assignment, adds the values on both left and right operands
What are objects used for?
Group together a set of variables and functions to represent something such as a person or a car
What are object properties?
Variable within an object
Describe object literal notation.
Properties of the object are stored within curly braces
How do you remove a property from an object?
delete object.property
What are the two ways to get or update the value of a property?
dot notation and bracket notation
What are arrays used for?
Storing a list of values
Describe array literal notation.
Putting the values of an array inside a bracket and separating each value with a comma.
How are arrays different from “plain” objects?
The key for each value in an array is a number. The number is the location in the array.
What number represents the first index of an array?
0
What is the length property of an array?
A method that returns how many values are in an array
How do you calculate the last index of an array?
array.length - 1
What is a function in JavaScript?
packages of code that can be called later in the program
Describe the parts of a function definition.
the function keyword an optional name zero or more parameters a code block an optional return statement
Describe the parts of a function call.
the function name followed by the arguments replacing the parameters in ( )
When comparing them side-by-side, what are the differences between a function call and a function definition?
The call is just the name and arguments
What is the difference between a parameter and an argument?
Parameteres are placeholders for arguments. The key thing to remember about parameters and arguments is that when we define a function, we declare parameters and that when we call a function, we pass it arguments.
Why are function parameters useful?
They let us pass data into the function
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.
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?
A method is a property of an object
How do you remove the last element from an array?
the pop method
How do you round a number down to the nearest integer?
Math.floor method. The floor method of the Math object
How do you generate a random number?
Math.random method. The random method of the Math object
How do you delete an element from an array?
The splice method. it needs start and delete count parameters to know index to delete and how many to delete from there.
How do you append an element to an array?
The push method
How do you break a string up into an array?
The split method
Do string methods change the original string? How would you check if you weren’t sure?
they don’t, they can create new strings stored to new variables, you can check by console logging them and MDN. There is no way to change an existing string.
Give 6 examples of comparison operators.
== is equal too === strictly equal != is not equal too !== strictly not equal greater than greater than or equals to less than less than or equals too
What is the purpose of an if statement?
to evaluate a conditional and execute code based on the evaluation
In simple terms, it is to make a decision.
Describe the syntax (structure) of an if statement.
key word, condition, opening curly brace, code to be executed, closing curly brace
What are the three logical operators?
&& and
|| or
!= not
How do you compare two different expressions in the same condition?
using logical operators
What is the purpose of a loop?
To check condition and run code certain number of times based on it
What is the purpose of a condition expression in a loop?
To give the conditions for the code to be executed and where to stop.
What does “iteration” mean in the context of loops?
Each time the loop runs
When does the condition expression of a while loop get evaluated?
before each iteration
When does the initialization expression of a for loop get evaluated?
before anything else
When does the condition expression of a for loop get evaluated?
before each loop iteration
When does the final expression of a for loop get evaluated?
the end of each loop iteration
Besides a return statement, which exits its entire function block, which keyword exits a loop before its condition expression evaluates to false?
Break
What does the ++ increment operator do?
It is the incremental operator adding one to the counter, and assigns it to the i variable.
How do you iterate through the keys of an object?
With a For In Loop
Why do we log things to the console?
To test if they are working, and to look at our data
What is a “model”?
a representation of something
Which “document” is being referred to in the phrase Document Object Model?
The HTML document