JavaScript Flashcards
What is the purpose of variables?
Variables store data that will be used in the future
How do you declare a variable?
var variableName
var keyword + variable name
How do you initialize (assign a value to) a variable?
Assignment operator ( = )
var variableName = expression;
What characters are allowed in variable names?
all Alphanumeric characters and the underscore symbol
tip: can’t start variable names with number and recommended to not start with a capital
What does it mean to say that variable names are “case sensitive”?
Uppercased letters and lowercased letters are completely different in the case of names
var Apple is not the same as var apple
What is the purpose of a string?
String stores text data
What is the purpose of a number?
number stores number data for a mathematical expression
What is the purpose of a boolean?
Boolean is used for yes or no situations
What does the = operator mean in JavaScript?
Assignment operator ( = )
How do you update the value of a variable?
Assigning the variableName with a new expression or value
var A = 3 A = 6
variable A is now 6
What is the difference between null and undefined?
null is used when the developer intentionally wants a variable to be empty.
undefined occurs when a variable has not been assigned a value and is most oftentimes a bug in the code
Why is it a good habit to include “labels” when you log values to the browser console?
console logging “labels” makes it easier for debugging when checking through many different variables
Give five examples of JavaScript primitives.
String
Number
Boolean
Null
Undefined
What data type is returned by an arithmetic operation?
number data type
What is string concatenation?
String concatenation refers to the ( + ) in a string expression
Attaches a string value to another string value
What purpose(s) does the + plus operator serve in JavaScript?
Addition or concatenation
What data type is returned by comparing two values (, ===, etc)?
Boolean (true or false)
What does the += “plus-equals” operator do?
Addition-Assignment Operator ( += )
Adds/Concatenates the left operand with a number/string and assigns the value back to the left operand
motto += 2
motto = motto + 2
What are objects used for?
Objects are used to sort and categorize sets of data
What are object properties?
Object properties are names of each category the data will be sorted into
{
propertyName: propertyValue;
}
Describe object literal notation.
var objectName = { propertyName: propertyValue, property2Name: property2Value };
How do you remove a property from an object?
Use delete keyword to remove property from an object
var object = { property1: property1Value }; delete object.property1;
What are the two ways to get or update the value of a property?
dot notation => object.property1
bracket notation => object[‘property1’]
What are arrays used for?
Arrays are used for creating/sorting/organizing data into ordered lists
Describe array literal notation.
var Array = [ value1, value2, value3 ];
How are arrays different from “plain” objects?
Arrays are ordered while objects are not
Arrays do not have titles/property names for each value while objects do
Array values can be called upon based on their order in the list while Object values must use specific names of their properties to call upon values
Length of an array can easily be accessed while object’s cannot
What number represents the first index of an array?
0
array[0]
What is the length property of an array?
length property is how many values are in the array
length of the array
How do you calculate the last index of an array?
array.length - 1
var lastIndexOfArray = array[ array.length - 1 ] ;
Why do we log things to the console?
Debugging
Developers are able to check for errors as they build their code
What is a method?
A function inside of an object
How is a method different from any other function?
A method is a function inside of an object.
JavaScript method is an object property that has a function value while a function is a block of code designed to perform a particular task.
How do you remove the last element from an array?
array.pop() method
pop() removes last element from an array and returns that element
How do you round a number down to the nearest integer?
Math.floor()
method
How do you generate a random number?
Math.random() method
How do you delete an element from an array?
splice() method
splice method changes contents of an array by removing or replacing existing elements and/or adding new elements in place
splce(start, deleteCount, item1, itemN)
How do you append an element to an array?
push() method
push method adds one or more elements to the end of an array and returns the new length of the array
How do you break a string up into an array?
split() method’
split method divdes a string into an ordered list of substring, puts these substrings into an array, and returns the array
Do string methods change the original string? How would you check if you weren’t sure?
String methods don’t normally change the original string and you can console.log the original string after the method has been used to make sure
Roughly how many string methods are there according to the MDN Web docs?
Around 30-40ish
Is the return value of a function or method useful in every situation?
The return value is not always useful in every situation.
Depends on the context it is used in
Roughly how many array methods are there according to the MDN Web docs?
Around 30ish
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN Mozilla Developer Network
Give 6 examples of comparison operators.
< > === !== >= <=
What data type do comparison expressions evaluate to?
Boolean (True or False)
What is the purpose of an if statement?
Test whether a condition is true or false and then proceeds to do any statement in its code block if true
Is else required in order to use an if statement?
Else is not required to use an if statement