Javascript Flashcards
What is the purpose of variables?
To hold values
How do you declare a variable?
var (name of var)
How do you initialize (assign a value to) a variable?
var (name of var) = value
What characters are allowed in variable names?
a-z, numbers, $, _
What does it mean to say that variable names are “case sensitive”?
The casing matters when trying to use variables
What is the purpose of a string?
To hold a collection of characters
What is the purpose of a number?
To hold numerical data
What is the purpose of a boolean?
To announce if a value is true or false. Likewise, it can announce 0 for false and 1 for true
What does the = operator mean in javascript
The assignment operator
How do you update the value of a variable?
re assign the value using the the name of the variable and = to new value
What is the difference between null and undefined?
Null is an object, but undefined is a type
Why is it a good habit to include “labels” when you log values to the browser console?
To identify what is being printed to the console.
Give 5 examples of JavaScript primitives
string, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
number
What is string concatenation?
2 strings combine and become 1 string
What purpose(s) does the + plus operator serve in Javascript?
Increment by 1
What data type is returned by comparing two values?
boolean
What does the += operator do?
Combines the left with the right
What are objects used for?
A collection of data
What are object properties?
data fields of an object
Describe object literal notation.
When you declare the object’s properties literally
How do you remove a property from an object?
Delete
What are the two ways to get or update the value of a property?
dot notation or bracket notation
What are arrays used for?
Collection of data
Describe array literal notation
create an array and place items within the indexes of the array
How are arrays different from “plain” objects?
objects do not require uniqueness
What number represents the first index of an array?
0
What is the length property of an array?
Tells how many elements are in an array
How do you calculate the last index of an array?
length -1
What is a function in JavaScript?
A set of statements that performs a task
Describe the parts of a function definition
function keyword, “name”, parameters within parenthesis, curly braces
Describe parts of a function call
function name, arguements
WHen comparing them side-by-side, what are the differences between a function call and function definition
the call only requires the name of the function and the possible arguments, the definition requires the keyword and the steps.
What is the difference between a parameter and an argument
parameter is what the function requires, but an argument is what the user passes to be used in the function
what two effects does a return statement have on the behavior of a function?
Exits the function and returns the value to the original call.
Why do we log things to the console?
To debug and check data
What is a method?
A function within a class
How is a method different from any other function?
It must be called using an object
How do you remove the last element of an array?
pop()
How do you round a number down to the nearest integer?
floor
How do you generate a random number?
random
How do you delete an element from an array?
splice
How do you append an element to an array?
push
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 replace it. You would log the string
Roughly how many string methods are there according to the MDN web docs?
25
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
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
> , =, !==
What data type do comparison expressions evaluate to?
boolean
What is the purpose of an if statement?
To evaluate different conditions
Is else required in order to use an if statement?
No
Describe the syntax(structure) of an if statement.
keyword if, condition, block
What are the three logical operators?
AND, OR, NOT
How do you compare two different expressions in the same condition?
&& or ||
What is the purpose of a loop?
To repeat lines of codes
What is the purpose of a condition expression in a loop?
To let it know when to exit the loop
What does iteration mean in the context of loops?
Incrementing a counter. So each repeated step
When does the condition expression of a while loop get evaluated?
At the beginning
When does the initialization of a for loop get evaluated?
At the beginning
When does the condition expression of a for loop get evaluated?
after the initialization and after increment
When does the final expression of a for loop get evaluated?
At the end of the code block
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 ++ increment operator do?
Increments the variable in use, but depending on if its in the front or back it will be used first then incremented or incremented then used
How do you iterate through the keys of an object?
for in
Why do we log things to the console?
Debugging and to find the results of data
What is a model?
The outline of an object
Which document is being referred to in the phrase Document Object Model
The HTML
What is the word object referring to in the phrase DOM
The elements in the html
What is a DOM tree?
tags
Give two examples of document methods that retrieve a single element from the dom.
querySelector, getElementByID
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll
Why might you want to assign the return value of a DOM query to a variable?
To retain that information
What console method allows you to inspect the properties of a DOM element object?
console.dir()
Why would a script tag need to be placed at the bottom of the HTML content instead of at the top?
The element would not be created at the time the script is ran. So it would not affect the HTML
What does querySelector() take as its argument and what does it return?
Object, element
What does document.QuerySelectorAll() take as its argument and what does it return?
object, nodeList
Why do we log things to the console?
To read about the object and debug
What is the purpose of the events and event handling?
Event is what occurs when the user interacts with the page and event handling is processing what to do when that event occurs
What do the [] square brackets mean in function and method syntax documentation?
optional arguments
What method of element objects lets you set up a function to be called when a specific type of event occurs?
eventlistener
What is a callback function?
function that is meant to be passed as part of another function’s argument
What object is passed into an event listener callback when the event fires?
event
What is the event.target? If you weren’t sure, how would you check? Where could you get more information about it?
element being targeted. html, console
What is the difference between adding () to callback functions in addEventListener?
When you use () the function is called, but it is not waiting for an event to fire. We pass the name in the function rather than the function itself. Trigger when the click happens, not when the event is made
What is the className property of element objects?
Allows you to change the class attribute of an element
How do you update the CSS class attribute of an element using JavaScript?
className
What is the textContent property of element objects?
Allows you to change the textContent attribute
How do you update the text within an element using JavaScript?
Update the textContent property.
Is the event parameter of an event listener callback always useful?
no
Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?
no
Why is storing information about a program in variables better than only storing it in the DOM?
tracking, don’t want to store in the DOM
What event is fired when a user places their cursor in a form control?
focus
What even is fired when a user’s cursor leaves a form control?
blur
What event is fired as a user changes the value of a form control?
input
What event is fired when a user clicks the submit button within a form?
the data in the form is passed