JavaScript Flashcards
What is the purpose of variables?
to hold data that can used or referenced later
How do you declare a variable?
use the keywords var, const, and let and then the variable name
How do you initialize (assign a value to) a variable?
use the assignment operator =
What characters are allowed in variable names?
letters, $, _ , and numbers but numbers cannot be the first character
What does it mean to say that variable names are “case sensitive”?
var number and var Number are two different variables
What is the purpose of a string?
to store and manipulate text
What is the purpose of a number?
math, quantities, count things
What is the purpose of a boolean?
true or false values, booleans exist for decision making. this or that
What does the = operator mean in JavaScript?
assignment. giving value to a variable
How do you update the value of a variable?
refer to the variable again and give it a new value
What is the difference between null and undefined?
both carry empty values, but null is intentionally assigned - it’s organic. undefined is inorganic. it comes from JavaScript. Baked into the language.
Why is it a good habit to include “labels” when you log values to the browser console?
it will give us a point of reference
Give five examples of JavaScript primitives.
string, number, boolean, undefined, and null
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combining two or more string values
What purpose(s) does the + plus operator serve in JavaScript?
adds numbers and concatenates strings
What data type is returned by comparing two values (<a>«/a>, <a>></a>, ===, etc)?</a>
boolean
What does the += “plus-equals” operator do?
take current value and addon whatever we stated and the result of that expression if the new value of the variable.
What are objects used for?
area to store data under one hood so everything is easier to access
What are object properties?
variables of the object
Describe object literal notation.
{
key: value,
key: value
}
How do you remove a property from an object?
delete keyword
What are the two ways to get or update the value of a property?
dot notation or bracket notation
What are arrays used for?
to store values with order
Describe array literal notation.
var example = [ 'thing1', thing2, thing3 ];
How are arrays different from “plain” objects?
arrays have order, indexes are not individually named, will repair themselves if an index is deleted, have a set length
What number represents the first index of an array?
0
What is the length property of an array?
stores the total amount of stuff in the array
How do you calculate the last index of an array?
subtract by 1 from the length property
What is a function in JavaScript?
a set of statements to perform a task that can help you repeat a certain task
Describe the parts of a function definition.
function name-of-function(parameter) { \_\_\_; return \_\_\_\_; }
Describe the parts of a function call.
name of function, (), and arguments if need be
When comparing them side-by-side, what are the differences between a function call and a function definition?
function call - actual values are being passed in
function definition - curly braces, a code block, function keyword
What is the difference between a parameter and an argument?
parameter - placeholder value
argument - the actual value
Why are function parameters useful?
without parameters, functions would always do the exact same thing, as in give the exact same result every time and the function can’t apply for other instances. ADAPTABILITY
What two effects does a return statement have on the behavior of a function?
returns a result and ends the function
Why do we log things to the console?
so we know if there are any errors in our code at any given time
What is a method?
function that’s a property of an object
How is a method different from any other function?
methods have to say where they’re coming from
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?
shift(), pop(), 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?
no. console log it or MDN