JavaScript Flashcards
What is the purpose of variables?
They are used to store data to utilize later on.
How do you declare a variable?
With the “var” keyword and the variable name.
How do you initialize (assign a value to) a variable?
With the “=” assignment operator and the variable value.
What characters are allowed in variable names?
Letters, dollar sign, underscore, numbers (cannot start with one)
What does it mean to say that variable names are “case sensitive”?
Variable names have to match exactly with correct capitalization.
What is the purpose of a string?
They hold text, letters and other characters.
What is the purpose of a number?
For counting or calculating values.
What is the purpose of a boolean?
- To determine which part of a script should run.
- Logic with binary states.
What does the = operator mean in JavaScript?
Assignment operator, used to assign a value.
How do you update the value of a variable?
The name of the variable with the new value.
What is the difference between null and undefined?
- Null is a nonexistent or invalid object or address
- Null has to be assigned.
- Undefined are for variables that have just been declared or to formal arguments for which there are no actual arguments.
Why is it a good habit to include “labels” when you log values to the browser console?
Labels in the console are good for knowing where the value stems from.
Give five examples of JavaScript primitives.
String, number, boolean, null, and undefined.
What data type is returned by an arithmetic operation?
A number.
What is string concatenation?
Combining string values.
What purpose(s) does the + plus operator serve in JavaScript?
- Adding together numbers, strings, and variables.
What data type is returned by comparing two values (, ===, etc)?
Boolean
What does the += “plus-equals” operator do?
Adds the value and assigns the result to the variable.
What are objects used for?
- Grouping together a set of variables and functions to create a model.
- A box of data related to each other grouped together.
What are object properties?
Properties are variables that tell us about the object.
Describe object literal notation.
Curly braces and its contents.
How do you remove a property from an object?
Use the delete keyword.
What are the two ways to get or update the value of a property?
Using dot and bracket notation.
What are arrays used for?
Lists or set of values that are related to each other.
Describe array literal notation.
Square brackets with each value separated by a comma.
How are arrays different from “plain” objects?
Arrays have index numbers, an order, and square brackets.
What number represents the first index of an array?
0
What is the length property of an array?
A true count of the amount of items within an array.
How do you calculate the last index of an array?
One less than the length of the array.
Why do we log things to the console?
It’s a debugging tool used to check errors.
What is a method?
Methods are functions which is a property of an object.
How is a method different from any other function?
Property of an object.
How do you remove the last element from an array?
pop method