Javascript Flashcards
What is the purpose of variables?
To temporarily store a value in a program
How do you declare a variable?
with the var keyword
How do you initialize (assign a value to) a variable?
with the assignment operator followed by a value
What characters are allowed in variable names?
letters, numbers(but not first), underscores, and dollar signs.
What does it mean to say that variable names are “case sensitive”?
each letter, undercase and lowercase, has a different ASCII value.
What is the purpose of a string?
to store words and shit
What is the purpose of a number?
to store number
What is the purpose of a boolean?
to store either a true or false value that will determine the outcome of certain decisions in your program.
What does the = operator mean in JavaScript?
it is the assignment operator that will assign a value to a variable.
How do you update the value of a variable?
by initializing it with no var keyword.
What is the difference between null and undefined?
null is an assigned blank value while undefined is a not yet defined value.
Why is it a good habit to include “labels” when you log values to the browser console?
it makes code reading easier
Give five examples of JavaScript primitives.
number, string, boolean, null, undefined
What data type is returned by an arithmetic operation?
a number
What is string concatenation?
combining strings with an addition sign
What purpose(s) does the + plus operator serve in JavaScript?
both adds numbers and concatenates strings
What data type is returned by comparing two values (, ===, etc)?
a boolean
What does the += “plus-equals” operator do?
it adds the value, or expression, to the right of the equals sign to value of the variable to the left and then assigns that value to the variable.
What are objects used for?
to store related data and put together a type of model of some sort.
What are object properties?
variables inside of an object
Describe object literal notation.
after var assignment opening curly brace followed by the key of the property then a colon then the value of that property. Each of those properties are separated by commas. End with a closing curly brace.
How do you remove a property from an object?
the delete keyword and the property
What are the two ways to get or update the value of a property?
dot notation and bracket notation
What are arrays used for?
for lists that don’t need to be ordered
Describe array literal notation.
after var assignment opening bracket then values separated by commas then closing bracket
How are arrays different from “plain” objects?
they use the index system instead of keys.
What number represents the first index of an array?
0
What is the length property of an array?
array.length and it gives the length of the array.
How do you calculate the last index of an array?
array.length - 1.
What is a function in JavaScript?
A set of code that is declared to complete a specific task
Describe the parts of a function definition.
the function key word, the name of the function, parameters if any, then the code block
Describe the parts of a function call.
the function name followed by arguments if any then a semi colon.
When comparing them side-by-side, what are the differences between a function call and a function definition?
a function call is when a function is to be used, the function definition is when a function is to be declared.
What is the difference between a parameter and an argument?
a parameter is the place holder variable in the function definition that will replaced when the function is called by the arguments listed in the function call. arguments are in the function call.
Why are function parameters useful?
the way to provide data for the functions and give different results so that the functions can be used in a variety of cases.
What two effects does a return statement have on the behavior of a function?
it both returns data to the function then stops the function.
Why do we log things to the console?
for debugging purposes to catch mistakes.
What is a method?
a function attached to an object
How is a method different from any other function?
it directly modifies the thing it is attached to. other than that they are the same
How do you remove the last element from an array?
using the pop method
How do you round a number down to the nearest integer?
using the math object with the floor method
How do you generate a random number?
using the math object with the random method
How do you delete an element from an array?
using the splice method on your array.
How do you append an element to an array?
using the push method on your array
How do you break a string up into an array?
using the split method with a string of a single space as your argument
Do string methods change the original string? How would you check if you weren’t sure?
no they only affect the return value. You can check by logging the original string to the console.
Is the return value of a function or method useful in every situation?
no, you don’t need to use it if you don’t have to.
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 give multiple paths for a conditional statement
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
the key word if followed by the conditional expression and then the code block
What are the three logical operators?
&&, ||, !
How do you compare two different expressions in the same condition?
with logical operators.
What is the purpose of a loop?
to repeat a certain section of code if necessary
What is the purpose of a condition expression in a loop?
to give that loop an exit route.
What does “iteration” mean in the context of loops?
how many times the loop runs
When does the condition expression of a while loop get evaluated?
before each iteration
When does the initialization expression of a for loop get evaluated?
its the very first step
When does the condition expression of a for loop get evaluated?
before each loop iteration runs
When does the final expression of a for loop get evaluated?
after the loop code block is excecated
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?
adds 1 and assigns it to the variable
How do you iterate through the keys of an object?
a for in loop
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?
Objects in the JavaScript language
What is a DOM Tree?
a tree representation of an HTML document
Give two examples of document methods that retrieve a single element from the DOM.
getElementByID, and querySelector
Give one example of a document method that retrieves multiple elements from the DOM at once.
querySelectorAll