Javascript Flashcards
What is the purpose of a number?
To assign numerical value
What is the purpose of a boolean?
To determine if something is true or false
What does the = operator mean in JavaScript?
It says that you are going to assign a value to a variable
How do you update the value of a variable?
By recalling the variable by the name and using the assignment operator to assign it a new value
What is the difference between null and undefined?
null is an assigned value. It means nothing.(intentional empty) undefined means a variable has been declared but not defined yet
Why is it a good habit to include “labels” when you log values to the browser console?
to help you debug, but if you do not include “labels”, it can be very confusing instead of helpful
Give five examples of JavaScript primitives.
string, number, boolean, undefined, and null.
What data type is returned by an arithmetic operation?
number
What is string concatenation?
Taking two strains and putting them together
What purpose(s) does the + plus operator serve in JavaScript?
To add values and concatenate
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds the value on the right, to the variable on the left, and then assigns that value back into the variable on the left
What are arrays used for?
To store a list of values
Describe array literal notation.
The values are assigned to the array inside a pair of square brackets, and each value is separated by a comma.
How are arrays different from “plain” objects?
It holds a list of related values in order, white object holds list of values out of order
What number represents the first index of an array?
0
What is the length property of an array?
It holds the number of items in the array
How do you calculate the last index of an array?
Subtracting 1 from the length of an array
What are objects used for?
To group together a set of variables and functions to create a model
What are object properties?
Variables that are part of an object.
Describe object literal notation.
Object is contained by curly braces,
You separate each key from its value by using a colon, separate each property and method with a comma.
How do you remove a property from an object?
Use keyword delete operator followed by dot notation
What are the two ways to get or update the value of a property?
Using dot notation or brackets notation
What is a function in JavaScript?
Functions allow you to package up code for use later in your program.
Describe the parts of a function definition:
Function keyword to bring a new function
An optional name
A comma-separated list of zero or more parameters
The start of the code block enclosed by curly braces
An optional return statement
Describe the parts of a function call.
The function’s name and a comma-separated list of zero or more arguments surrounded by ()
When comparing them side-by-side, what are the differences between a function call and a function definition?
Call, recalls the function and executes the code to run, definition defines and states what the code is going to do
What is the difference between a parameter and an argument?
Parameters are used to define a function, arguments are used to call a function.
Why are function parameters useful?
Because they allow to function to be more flexible
What two effects does a return statement have on the behavior of a function?
Causes the function to produce a value we use in our program
Prevents any more code in the code block from being run
Why do we log things to the console?
To use as a debugging tool and learning to play and learn about JS
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 associated with an object while a function is not
How do you remove the last element from an array?
pop()
How do you round a number down to the nearest integer?
floor()
How do you generate a random number?
Math.random()
How do you delete an element from an array?
splice()
How do you append an element to an array?
push() unshift()
How do you break a string up into an array?
split()
Do string methods change the original string? How would you check if you weren’t sure?
No they don’t change original string, assigning original string to a var and checking with new string
Roughly how many string methods are there according to the MDN Web docs?
60+ methods
Is the return value of a function or method useful in every situation?
no
Roughly how many array methods are there according to the MDN Web docs?
30+ methods
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.
> , < , >= , <= , === , and !==
What data type do comparison expressions evaluate to?
Boolean
What is the purpose of an if statement?
guides a program to make decisions based on specified criteria
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
If ( exp ) {
Code block to run
}
What are the three logical operators?
And or not
How do you compare two different expressions in the same condition?
With and / or logical operators
What is the purpose of a loop?
To perform repeated tasks based on a condition
What is the purpose of a condition expression in a loop?
Tells the loop when to stop
What does “iteration” mean in the context of loops?
Repetition of a function or process
When does the condition expression of a while loop get evaluated?
before executing the statement. And one after
When does the initialization expression of a for loop get evaluated?
Before each loop iteration, just once
When does the condition expression of a for loop get evaluated?
Each time before the loop runs
When does the final expression of a for loop get evaluated?
At 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 statement
What does the ++ increment operator do?
Increase the number by 1 and reassigns the value back into variable
How do you iterate through the keys of an object?
Using a for in loop
Why do we log things to the console?
To debug and make sure things are working.
What is a “model”?
The representation of something
Which “document” is being referred to in the phrase Document Object Model?
The document which is being represented on the web page