javascript Flashcards
What is the purpose of variables?
Store data and information.
How do you declare a variable?
Start with a variable keyword, followed by the variable name and followed by a semicolon.
How do you initialize (assign a value to) a variable?
use an assignment operator (=)
What characters are allowed in variable names?
a-z(case sensitive), _(underscore), dollar sign, camel case, numbers.
What does it mean to say that variable names are “case sensitive”?
App vs app means two different variables.
What is the purpose of a string?
Store text data and They are frequently used to add
new content into a page and they
can contain HTML markup.
What is the purpose of a number?
Calculating. determining the size of the screen, moving the position of an element on a page, or setting the amount of time an element should take to fade in.
What is the purpose of a boolean?
true or false.
What does the = operator mean in JavaScript?
assign the value
How do you update the value of a variable?
assign another value?
What is the difference between null and undefined?
null is an assigned value, undefined means there is a declared available but not defined.
Why is it a good habit to include “labels” when you log values to the browser console?
It will be easier to locate the data you are looking for.
Give five examples of JavaScript primitives.
string, number, boolean, undefined, and null.
What are objects used for?
store data
What are arrays used for?
store a collection of data such as lists
What number represents the first index of an array?
0
What is the length property of an array?
the name of the array.length
What is a function in JavaScript?
A block of code that can be stored and reused.
What is the difference between a parameter and an argument?
the parameter is the name and the argument is the real value.
Why are function parameters useful?
It can store different types of data.
What two effects does a return statement have on the behavior of a function?
no code will be run after the return statement.
Why do we log things to the console?
Console log provides you data and checks things work correctly.
What is a method?
is a function?
How is a method different from any other function?
need to look up.
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(), 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?
You cannot change the original string.
Roughly how many string methods are there according to the MDN Web docs?
roughly 30 methods.
Is the return value of a function or method useful in every situation?
They are not always useful. Sometimes the return value does not give you much information.
Roughly how many array methods are there according to the MDN Web docs?
a lot of them
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
Why do we log things to the console?
To test the code runs properly.
What is a “model”?
?
Which “document” is being referred to in the phrase Document Object Model?
html?
What is the word “object” referring to in the phrase Document Object Model?
elements in the html
What is a DOM Tree?
The structure of the html?
Give two examples of document methods that retrieve a single element from the DOM.
queryselector()
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?
easily to locate?
What console method allows you to inspect the properties of a DOM element object?
console.dir()
Why would a tag need to be placed at the bottom of the HTML content instead of at the top?
The browser needs to parse all of the elements in the HTML page before the JavaScript code can access them.
What does document.querySelector() take as its argument and what does it return?
CSS selector.