JavaScript Flashcards
What is the purpose of variables?
To store values to use later on
How do you declare a variable?
var name
How do you initialize (assign a value to) a variable?
var name = “xxxx”
What characters are allowed in variable names?
letters (uppercase, lowercase), $, underscore _ , numbers (can’t start with numbers)
What does it mean to say that variable names are “case sensitive”?
lower case and upper case are not exchangeable in variable name
What is the purpose of a string?
to store text
What is the purpose of a number?
to store numeric value
What is the purpose of a boolean?
to store binary values and make decisions
What does the = operator mean in JavaScript?
assignment operator (to put value in something)
How do you update the value of a variable?
name = new value (do not need to redeclare var after it’s been declared first time)
What is the difference between null and undefined?
null is an assigned value (intentional). undefined = empty
Why is it a good habit to include “labels” when you log values to the browser console?
to make it easier to debug
Give five examples of JavaScript primitives.
string, number, boolean, null, undefined,
What data type is returned by an arithmetic operation?
number
What is string concatenation?
adding strings together
What purpose(s) does the + plus operator serve in JavaScript?
add numerical values or concatenate strings
What data type is returned by comparing two values (, ===, etc)?
Boolean - true or false
What does the += “plus-equals” operator do?
add onto current variable value
What are objects used for?
to store relevant data together (grouping)
What are object properties?
to store additional data relevant to objects
Describe object literal notation.
{
property : value
}
How do you remove a property from an object?
delete operator
What are the two ways to get or update the value of a property?
dot notation and bracket notation
What are arrays used for?
store multiple values
Describe array literal notation.
list of zero or more expressions, each of which represents an array element, enclosed in square brackets
How are arrays different from “plain” objects?
Arrays have an order & numeric indexes, and [ ]
What number represents the first index of an array?
0
What is the length property of an array?
true count of values stored in an array
How do you calculate the last index of an array?
length - 1
What is a function in JavaScript?
repeatable, reusable block of code with the potential to receive and return different values.
Describe the parts of a function definition.
keyword function, name of the function, parameter, opening curly brace
function functionName (parameter) { }
Describe the parts of a function call.
name of the function followed by arguments
getFunction(2,2);
When comparing them side-by-side, what are the differences between a function call and a function definition?
function definition has keyword and code block function call has arguments and values
What is the difference between a parameter and an argument?
parameter is a placeholder
argument is data provided for the function call and returns a value
Why are function parameters useful?
they’re a placeholder
What two effects does a return statement have on the behavior of a function?
returns the value and
exits out of the function code block
Why do we log things to the console?
to display and debug
What is a method?
function that stores data about the object
How is a method different from any other function?
How do you remove the last element from an array?
“top” method - take off last item
How do you round a number down to the nearest integer?
floor method
How do you generate a random number?
random method
How do you delete an element from an array?
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?
Roughly how many string methods are there according to the MDN Web docs?
Is the return value of a function or method useful in every situation?
Roughly how many array methods are there according to the MDN Web docs?30
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 determine whether to perform a function or not
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
if (condition) { code block }
What are the three logical operators?
&&, ||, !
How do you compare two different expressions in the same condition?
&& or || operator
What is the purpose of a loop?
Repeated block of code happening under some condition
What is the purpose of a condition expression in a loop?
tell the function when to stop running
What does “iteration” mean in the context of loops?
one repetition of a loop code block
When does the condition expression of a while loop get evaluated?
before each iteration (before it runs)
When does the initialization expression of a for loop get evaluated?
in the very beginning (first step)
When does the condition expression of a for loop get evaluated?
after initialization and before the code block runs
When does the final expression of a for loop get evaluated?
after 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?
adds 1 to the variable and assigns it to the var
How do you iterate through the keys of an object?
for-in loop
Why do we log things to the console?
to test the output
What is a “model”?
representation (not the actual thing, but the recreation of it, usually in a smaller scale)
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?
Object = data type, object, in javascript