JavaScript Flashcards
What is the purpose of variables?
Store bits of data.
How do you declare a variable?
create a variable using
var(variable keyword) then providing it a name quantity(variable name): var quantity;
How do you initialize (assign a value to) a variable?
By using the =(assignment operator) sign followed by the data.
What characters are allowed in variable names?
a-z, 0-9, $ and _
What does it mean to say that variable names are “case sensitive”?
You can have two variables with different cases that refer to different variables but use the same word.
What is the purpose of a string?
To store written text often times information about a user.
What is the purpose of a number?
Used to count the items of things or doing mathematical equations.
What is the purpose of a boolean?
Gives us the ability to make decisions.
What does the = operator mean in JavaScript?
It is the assignment operator.
How do you update the value of a variable?
use the variable name followed by = and the new value:
fullname = Kalen Cobb
What is the difference between null and undefined?
Null = used by a developer to denote future use
undefined is usually accidental and the computer is telling you it is undefined.
Why is it a good habit to include “labels” when you log values to the browser console?
So you can keep track of your output.
Give some examples of JavaScript primitives.
strings, numbers, booleans, null, undefined.
What datatype is returned by an arithmetic operation?
Number
What is string concatenation?
The conjoining of two or more strings together using the + operator.
What purpose(s) does the + plus operator serve in JavaScript?
Addition and Concatenation
What data type is returned by comparing two values (, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
Addition Assignment
adds whatever is on the right side to the value of the variable and then the result of that expression is assigned to the variable.
What are objects used for?
A box to keep related stuff together
What are object Properties?
Another way to store data, exclusive to the specific variable
Describe object literal notation.
Properties and values nested inside curly braces.
How do you remove a property from an object?
delete operator (although this is rare)
What are the two ways to get or update the value of a property in JavaScript?
dot notation or bracket notation
What are arrays used for?
Storing lists of data
Describe array literal notation.
values nested inside square brackets.
How are arrays different from “plain” objects?
Arrays are an ordered list with numeric indexes
What is the length property of an array?
A property that holds the number of items in an Array
How do you calculate the last index of an array?
array.length -1
Describe the parts of a function definition.
- Function keyword
- Function name (optional)
- Comma separated parameters surrounded by parenthesis ( ).
- Function code block starting with an opening curly brace {
- Optional return statement
- end of the functions code block indicated by a closing curly brace }
What is a function in JavaScript?
A group of actions that are repeatable
When comparing them side-by-side, what are the differences between a function call and a function definition?
The Definition is followed by the code block which holds the tasks, while the Call is followed by parentheses only.
What is the difference between a parameter and an argument?
A parameter is a placeholder for the argument that is passed to it.
When comparing them side-by-side, what are the differences between a function call and a function definition?
The function keyword will not be present when being called.
What is the difference between a parameter and an argument?
A parameter is a variable placeholder for the argument that is passed to it.
Why are function parameters useful?
We can input data we didn’t previously have when writing 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.
Why do we log things to the console?
To debug our work during the development phase.
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 being used ON an object (object.method())
How do you remove the last element from an array?
.pop()
How do you round a number down to the nearest integer?
Math.floor()
How do you generate a random number?
Math.random()
How do you delete an element from an array?
Use .splice() method
How do you append an element to an array?
.push() method
How do you break a string up into an array?
.split() method
Do string methods change the original string? how would you check if you weren’t sure?
No and look at the documentation.
Roughly how many strings methods are there according to the MDN Web docs?
Look at the Docs!
What three-letter acronym should you alwasy include in your google search about a JavaScript method or CSS property?
MDN
Is the return value of a function or method useful in every situation?
Not really.
Roughly how many array methods are there according to MDN web docs?
look at the docs!
What data type do comparison expressions evaluate to?
Boolean
Is else required in order to use an if statement?
No
Describe the syntax (structure) of an if statement.
Keyword if (condition in parenthesis) opening curly brace
code
closing curly brace
What are three logical operators?
&&(logical and), ||(logical or), ! (logical not)
How do you compare two different expressions in the same condition?
Using && and/or ||
How do you compare two different expressions in the same condition?
Using && and/or ||
What is the purpose of a loop?
Allow us to do a repeatable action.
What is the purpose of a condition expression in a loop?
To check whether or not the loop should stop.
What does “iteration” mean in the context of loops?
The number of times we run the action.
When does the condition expression of a while loop get evaluated?
Immediately and before every iteration.
When does the initialization expression of a for loop get evaluated?
Before anything else but only once.
When does the condition expression of a for loop get evaluated?
After the initialization and with every iteration.
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
What does the ++ increment operator do?
Increases by an increment of one after it is used.
How do you iterate through the keys of an object?
Use a for…in loop.
Why do we log things to the console?
To check our work and inspect our data.
Verification and inspecting data.
What is a “model”?
A system or thing used as an example to follow or imitate.
Which “document” is being referred to in the phrase Document Object Model?
The HTML document
What is the word “object” referring to in the phrase Document Object Model?
JavaScript Objects
What is a DOM Tree?
A model of a webpage consisting of all of the elements and their nodes including the parent and any child and other descendents.
Give examples of document methods that retrieve a single element from the DOM
getElementById()
querySelector() (use this primarily)