Javascript Flashcards
What are arrays used for?
Storing lists, especially lists of ordered or related data.
Describe array literal notation.
Comma-delineated items between square brackets.
[ item1, item2 . . . ]
How are arrays different from “plain” objects?
The keys in arrays are numbers instead of strings; Arrays are numerically indexed.
What number represents the first index of an array?
0
What is the length property of an array?
The number of items in the array.
How do you calculate the last index of an array?
arrayLength - 1
What are objects used for?
They group together related information (ie. variables and functions)
In OOP (object oriented programming) objects are used to model areal-world objects.
What are object properties?
Key-value pairs consisting of a property and its value.
Describe object literal notation.
Comma-delineated key-value pairs between curly braces.
{ prop1: val1, prop2: val2, . . . }
How do you remove a property from an object?
The delete operator.
What are the two ways to get or update the value of a property?
Dot notation (using member operator) and bracket notation
What data type is returned by an arithmetic operation?
number
What is string concatenation?
Joining strings together
What purpose(s) does the + plus operator serve in JavaScript?
Adding numbers and concatenating strings
What data type is returned by comparing two values (, ===, etc)?
boolean
What does the += “plus-equals” operator do
It is shorthand for performing addition or concatenation and then assigning the result to the variable on the left.
What is the purpose of variables?
Temporarily store pieces of data while a program is running.
How do you declare a variable?
Using the keyword const, let, or var followed by the variable name
How do you initialize (assign a value to) a variable?
using the assignment operator (=) var varName = aValue;
What characters are allowed in variable names?
Letters, numbers, $, and _ (underscore). Variables names cannot start with a number.
What does it mean to say that variable names are “case sensitive”?
Lower and upper case letters are considered different characters.
What is the purpose of a string?
Store and represent text date/characters
What is the purpose of a number?
Represent/store numeric data so you can do math/arithmetic.
What is the purpose of a boolean?
To represent/store binary data which lets you do logic
What is the difference between null and undefined?
Undefined means ‘no value given yet’; null explicitly means ‘nothing’ or ‘intentional absence’
Why is it a good habit to include “labels” when you log values to the browser console?
Helps with debugging since a label can indicate where and what variable a value comes from.
Give five examples of JavaScript primitives
string, number, boolean, undefined, null, …symbol is also a type