Javascript Flashcards
What is the purpose of variables?
To give us a location to store data to use in the future
How do you declare a variable?
By using var, setting a variable name, then using the = operator to set it to a value
How do you initialize (assign a value to) a variable?
Using the = operator
What characters are allowed in variable names?
Letters, numbers, dollar sign, underscore
What does it mean to say that variable names are “case sensitive”?
It is sensitive to capitalizations
What is the purpose of a string?
To store text
What is the purpose of a number?
To store a numerical or mathematical value
What is the purpose of a boolean?
To store a true or false value
What does the = operator mean in JavaScript?
It’s used to set a variable to a value (assignment operator)
How do you update the value of a variable?
State the variable name, assignment operator, set it to new value
What is the difference between null and undefined?
Null is an assigned value and explicitly means nothing. Undefined means a variable has been declared, but the value has not yet been defined
Why is it a good habit to include “labels” when you log values to the browser console?
It adds readability and gives more context
Give five examples of JavaScript primitives.
String, number, boolean, null, undefined
What data type is returned by an arithmetic operation?
A number data type
What is string concatenation?
When you combine multiple strings using the + operator
What purpose(s) does the + plus operator serve in JavaScript?
To perform addition or concatenate multiple strings together to create one value
What data type is returned by comparing two values (, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
A shorthand operator that allows you to add the value from the right operand to the left operand, then assigns the new value to the left operand
What are objects used for?
To store multiple data points or properties within a variable
What are object properties?
A collection of values attached to an object
Describe object literal notation.
A variable assigned to multiple properties using curly brackets, then a list of properties and their values separated by a colon, comma to separate multiple properties.
How do you remove a property from an object?
Keyword “delete” then the object.property or object[‘property’]
What are the two ways to get or update the value of a property?
getAttribute, setAttribute
What are arrays used for?
To store a list of elements that we can access by a single variable. To-do lists, lists of users, etc are all great ways to leverage arrays
Describe array literal notation.
Declare var, variable name, assignment operator, square brackets, and put each value in the brackets, separated by commas
How are arrays different from “plain” objects?
Objects use properties and values, while arrays have values only. Objects don’t have an order, while arrays do. Objects use dot notation while arrays use bracket notation.
What number represents the first index of an array?
0
What is the length property of an array?
It tells you how many items are in your array
How do you calculate the last index of an array?
Array.length minus 1
What is a function in JavaScript?
A set of statements that performs a task or calculates a value
Describe the parts of a function definition.
Function keyword, function name, parenthesis for parameters, curly bracket for function code block, return keyword, then expression, closed curly bracket to close declaration
Describe the parts of a function call.
Function name, parenthesis, arguments.
When comparing them side-by-side, what are the differences between a function call and a function definition?
Parameters vs arguments. Function definition has function key work and code block. Function call contains the function name and parenthesis to call it.
What is the difference between a parameter and an argument?
Parameters are properties of a function definition. Arguments are properties of a function call.
Why are function parameters useful?
Parameters allow us to pass information or instructions into functions
What two effects does a return statement have on the behavior of a function?
A return statement ends the execution of a function, and returns control to the calling function
Why do we log things to the console?
To ensure the code is working properly and to debug code
What is a method?
a property of an object that contains a function definition
How is a method different from any other function?
A method has to be attached to an object
How do you remove the last element from an array?
Pop method
How do you round a number down to the nearest integer?
Floor method
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?
They do NOT change the original string. Do it then console log it.
Roughly how many string methods are there according to the MDN Web docs?
40 or so
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 or so
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 guide a program to make decisions based on specified criteria
Is else required in order to use an if statement?
no
Describe the syntax (structure) of an if statement.
If keyword, parenthesis for condition, curly brace for condition code block, return
What are the three logical operators?
&&, ||, and !
How do you compare two different expressions in the same condition?
Logical operators
What is the purpose of a loop?
Loops allow you to repeat a process over and over without having to write the same (potentially long) instructions each time you want your program to perform a task.
What is the purpose of a condition expression in a loop?
an expression that is tested each time the loop repeats. As long as condition is true, the loop keeps running.
What does “iteration” mean in the context of loops?
Is the single time a loop code block executes
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?
Beginning of the loop
When does the condition expression of a for loop get evaluated?
Before each iteration takes place
When does the final expression of a for loop get evaluated?
After each iteration takes place
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?
Increases the value of a variable by 1, then substitutes the new value
How do you iterate through the keys of an object?
For in loop
Why do we log things to the console?
To see what the code is doing / debugging
What is a “model”?
Contains all the logic in Javascript
Which “document” is being referred to in the phrase Document Object Model?
The HTML document