JavaScript Flashcards
What is the purpose of variables?
To store data so we can access them in the future and multiple times
How do you declare a variable?
Using the variable keyword ‘var’
How do you initialize (assign a value to) a variable?
Using the assignment operator “=” after declaring the variable
What characters are allowed in variable names?
Letters, numbers (but cannot start with a number), dollar signs and underscore
What does it mean to say that variable names are “case sensitive”?
The same word with a capital letter would be different variable names
What is the purpose of a string?
To save text content or series or characters
What is the purpose of a number?
To save for counting and calculating sums
What is the purpose of a boolean?
To save for when there are only two values “True & False” or “Yes & No”. Used for decisions
What does the = operator mean in JavaScript?
It is an assignment operator. It assigns values to variables
How do you update the value of a variable?
To reassign it by using the declared value
What is the difference between null and undefined?
Null is an intentional absence of a value (var hello = null) whereas undefined is a variable that hasn’t been initialized yet (just declared ‘var hello;’)
Why is it a good habit to include “labels” when you log values to the browser console?
So you can easily see what is being logged
Give five examples of JavaScript primitives. String, boolean, number, null, undefined
What data type is returned by an arithmetic operation?
An expression
What is string concatenation?
Joining two or more string values to create a new string
What purpose(s) does the + plus operator serve in JavaScript?
To add number values or to concatenate string values
What data type is returned by comparing two values (, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
Adds or concatenates the value of the right to the left of the operator and then assigns the result of the expression to the to the variable on the left
What are objects used for?
To group together a set of variables and functions around one subject
What are object properties?
A variable within an object
Describe object literal notation.
Define a new variable and assign it to an object literal using curly braces. Using property and values
How do you remove a property from an object?
Delete operator followed by dot notation object.property
What are the two ways to get or update the value of a property?
Using the dot notation or the bracket notation
What are object methods?
A function within an object
What are arrays used for?
Arrays store a list of values that are related to each other
Describe array literal notation.
Define a new variable and assign it to an array literal notation using square brackets.
How are arrays different from “plain” objects?
They are listed in a number index
What number represents the first index of an array?
0
What is the length property of an array?
.length - tells you how many properties are in an array
How do you calculate the last index of an array?
Object.length - 1
What is a function in JavaScript?
Special type of object that can be called multiple times
Describe the parts of a function definition.
Function keyword, optional name, zero or more parameters surrounded by parentheses, start of code block, optional return statement, closing code block
Describe the parts of a function call.
Function name with parentheses with or without arguments
When comparing them side-by-side, what are the differences between a function call and a function definition?
Call is to run/pass the arguments. Function definition has a code block with ‘instructions’.
What is the difference between a parameter and an argument?
Parameter is what is listed in the function definition. Argument is the function call (actual values passed)
Why are function parameters useful?
Placeholder - to pass additional information into the function
What two effects does a return statement have on the behavior of a function?
It causes the function to produce a value and prevents any more code in the function’s code block from being run
Why do we log things to the console?
To check our progress and see if the outcome is what we are expecting or not
What is a method?
A function that is stored within a property of an object
How is a method different from any other function?
A function can be called directly by its name, but a method is called using the dot notation
How do you remove the last element from an array?
Using the method .pop() - it also returns that removed element
How do you remove the first element from an array?
Using the method .shift() - it also returns that removed element
How do you round a number down to the nearest integer?
Using the object & method Math.floor()
How do you generate a random number?
Using the object & method Math.random()
function getRandomNumberInRange(start, end) { var randomNum = Math.floor(math.random() * (end - start) + 1) + start; return randomNum; }
How do you delete an element from an array?
Using the method .splice()
How do you append an element to an array?
Using the method .push()
How do you break a string up into an array?
Using the method .split()
Do string methods change the original string? How would you check if you weren’t sure?
No. By console logging the variable of the original string.
Roughly how many string methods are there according to the MDN Web docs?
37
Is the return value of a function or method useful in every situation?
No, we don’t always need to return.
Roughly how many array methods are there according to the MDN Web docs?
39
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
“MDN”
How do you prepend an element to an array?
Using the method .unshift()