JavaScript Flashcards
What is the purpose of variables?
A placeholder (container) to temporarily store bits of information/data in memory.
How do you declare a variable?
Use a variable keyword (const, let, var) and then assign it a variable name.
How do you initialize (assign a value to a variable)?
Use the assignment operator (=).
What characters are allowed in variable names?
-Variables must only start with a letter, dollar sign ($), or and underscore ().
-Variables can contain letters, numbers, dollar sign ($), or an underscore().
DO NOT USE a dash (-) or a period (.) in a variable name.
-Variables CANNOT use keywords or reserved words.
What does it mean to say that variable names are “case sensitive”?
It means that Score and score would be different variables, but it is bad practice to create two variables that have the same name using different cases.
What is the purpose of a string?
Storing and manipulating text data.
What is the purpose of a number?
Storing and manipulating numerical data (maths).
What is the purpose of a boolean?
A logical data type that can have only the values true or false.
(Booleans allow for making decisions in JavaScript).
What does the = operator mean in JavaScript?
Assignment.
How do you update the value of a variable?
Reassign it.
What is the difference between null and undefined?
Undefined is a variable that refers to something that doesn’t exist, and the variable isn’t defined to be anything. (Accidental emptiness).
-Programmers will NEVER use undefined as a variable.
Null is a variable that is defined but is missing a value. (Purposeful emptiness).
-Programmers will sometimes use null as a variable.
Why is it a good habit to include “labels” when you log values to the browser console?
-Make things more clear.
-To help debug.
Give seven examples of JavaScript primitives.
-string.
-number.
-boolean.
-undefined.
-null.
-bigint.
-symbol.
What are objects used for?
To store multiple pieces of data, that are related to each other.
What are objects properties?
A individual piece of named data that stores a value, within an object.
Describe object literal notation.
An object literal with key: value pairs is assigned to a variable.
What are the two ways to get or update the value of a property?
Dot notation.
Square bracket notation.
What are arrays used for?
-Organizing data.
-Working with a list or a set of values
that are related to each other.
-Especially helpful when you do not
know how many items a list will contain.
-Storing a list of information, either order is very important or not important.
Describe array literal notation.
- Give the array a name. (Make a variable).
-Values are then assigned to the array inside a pair of square brackets, and each value is separated by a comma.
-(Array values do not need to be the same data type, but often are).
How are arrays different from “plain” objects?
*** Arrays always start with a length (index 0).
- Arrays are a special type of object. They hold a related set of key/value pairs (like all objects), but the key for each value is its index number.
-Arrays have index numbers for keys.
-Arrays, almost always, contain the same data type.
What number represents the first index of an array?
Zero.
What is the length property of an array?
-The length property sets or returns the number of elements in an array.