JAVASCRIPT Flashcards
What is the purpose of variables?
the purpose of variables is to not lose track of the variable in your code
How do you declare a variable?
with the var keyword
How do you initialize (assign a value to) a variable?
with the = opertor
What characters are allowed in variable names?
$, _,
What does it mean to say that variable names are “case sensitive”?
if you have a variable with a capital S and lower case s they are different
What is the purpose of a string?
to have a number of letters to make up something
What is the purpose of a number?
the prupose of a number is to hold a numeric value.
What is the purpose of a boolean?
to determine true or false
What does the = operator mean in JavaScript?
it is the assignment operator
How do you update the value of a variable?
variable name = and then the value you want to give it
What is the difference between null and undefined?
null is done intentioanlly and undefined is not
Why is it a good habit to include “labels” when you log values to the browser console?
so you know what data is being output and you can keep track of what you are logging
Give five examples of JavaScript primitives.
string, number, boolean, undefined, null, array object
What data type is returned by an arithmetic operation?
numeric data type
What is string concatenation?
the joining of one strring and another string to make a whole string
What purpose(s) does the + plus operator serve in JavaScript?
it allows us to add strings or numerical values together
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds and assigns new value to current value
What are objects used for?
a data type that allows you to store data in indivisual keys
What are object properties?
indivisual keys that hold a value
Describe object literal notation.
var hello = { }
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?
. notation and bracket notation
What are arrays used for?
arrays are used to store multiple values of data kind of like a shopping list
Describe array literal notation.
[ ]
How are arrays different from “plain” objects?
array hold and index and object do not
What number represents the first index of an array?
0
What is the length property of an array?
the length property stores values and lets a use know the length of an an array
How do you calculate the last index of an array?
subtract 1 from the length of the array
What is a function in JavaScript?
a set of statments that perform tasks to calculate a value
Describe the parts of a function definition.
function defention, keyword, parameter lsit
Describe the parts of a function call.
function name ()
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call uses function name with () and any argument defention has a function keyword and code block()
What is the difference between a parameter and an argument?
a paremeter holds a place so that you can add whatever argument you want later.
Why are function parameters useful?
Function parameters are useful because they act as placeholders for data.
What two effects does a return statement have on the behavior of a function?
a return statement stops the code once the return statement has been executed.
Why do we log things to the console?
to see what the output is that we are getting
What is a method?
a function which is a property of an object
How is a method different from any other function?
A method, like a function, is a set of instructions that perform a task. The difference is that 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?
Math.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( )
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?
All string methods return a new string. They don’t modify the original string. F
Roughly how many string methods are there according to the MDN Web docs?
80-85
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?
40-50
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?
true or false
What is the purpose of an if statement?
Is else required in order to use an if statement?
No
Describe the syntax (structure) of an if statement.
if( ){
}
What are the three logical operators?
logical and &&
logical or ||
logical not !
How do you compare two different expressions in the same condition?
logical and logical or operator
What is the purpose of a loop?
the purpose of a loop is to run something several times until a condition is met
What is the purpose of a condition expression in a loop?
What does “iteration” mean in the context of loops?
it is the repetition of a process
When does the condition expression of a while loop get evaluated?
second after the initializtion
When does the initialization expression of a for loop get evaluated?
when the loop starts.
When does the condition expression of a for loop get evaluated?
When does the final expression of a for loop get evaluated?
after the code block runs and before the condition runs again
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?
the increment operator increments a value
How do you iterate through the keys of an object?
The Object. keys() method was introduced in ES6. It takes the object that you want to iterate over as an argument and returns an array containing all properties names (or keys)
Why do we log things to the console?
we log things to the console to see what the output is
What is a “model”?
a model is a piece that is a replica of something else
Which “document” is being referred to in the phrase Document Object Model?
HTML document
What is the word “object” referring to in the phrase Document Object Model?
the nodes
What is a DOM Tree?
Document object model that stores parent elements and their children elements
Give two examples of document methods that retrieve a single element from the DOM.
document. querySelector()
document. getElementById()
Give one example of a document method that retrieves multiple elements from the DOM at once.
document.querySelectorAll()
Why might you want to assign the return value of a DOM query to a variable?
So that you can document it again
What console method allows you to inspect the properties of a DOM element object?
the dir. direcotry method
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
So that we can let the document know that we are going to include javascript
What does document.querySelector() take as its argument and what does it return?
css selector and returns the first element with that selector
What does document.querySelectorAll() take as its argument and what does it return?
csss selector and it returns all elements that have the id selectors
What is the className property of element objects?
The className property of the Element interface gets and sets the value of the class attribute of the specified element.
How do you update the CSS class attribute of an element using JavaScript?
setAttribute()
What is the textContent property of element objects?
The textContent property sets or returns the text content of the specified node, and all its descendants.
How do you update the text within an element using JavaScript?
using the document.querySelector(‘ ).textcontent
Is the event parameter of an event listener callback always useful?
no it is not
Would this assignment be simpler or more complicated if we didn’t use a variable to keep track of the number of clicks?
more complicated
Why is storing information about a program in variables better than only storing it in the DOM?
What does the transform property do?
the transform property lets you move the element around in differne ways
Give four examples of CSS transform functions.
What event is fired when a user places their cursor in a form control?
the focus event
What event is fired when a user’s cursor leaves a form control?
the blur event
What event is fired as a user changes the value of a form control?
the input event
What event is fired when a user clicks the “submit” button within a ?
submit event
What does the event.preventDefault() method do?
it stops the default method from happening
What does submitting a form without event.preventDefault() do?
The preventDefault() method cancels the event if it is cancelable, meaning that the default action that belongs to the event will not occur
What property of a form element object contains all of the form’s controls.
form
What property of a form control object gets and sets its value?
.value gets and sets property of a form control
What is one risk of writing a lot of code without checking to see if it works so far?
You can not see where you messed up and it is harder to find where you made a mistake
What is an advantage of having your console open when writing a JavaScript program?
You can see where there is an error as it happens
Give two examples of media features that you can query in an @media rule.
min-width max-width
Which HTML meta tag is used in mobile-responsive web pages?
viewport
Does the document.createElement() method insert a new element into the page?
no it does not
How do you add an element as a child to another element?
with the appendChild() method
What do you pass as the arguments to the element.setAttribute() method?
we pass the classname or attributes we want to include on that element
What steps do you need to take in order to insert a new element into the page?
document.createElementById(‘div”)
What is the textContent property of an element object for?
we can use it to set and change the text of an element from the DOM
Name two ways to set the class attribute of a DOM element.
setAttribute and .className