JavaScript Flashcards
What is the purpose of variables?
Variables are used to store information for the computer to be able to reference back to. It brings permanence to data.
How do you declare a variable?
You declare a variable with the var keyword followed by the variable name. A variable can start with a letter, $, or _
var fullName
How do you initialize (assign a value to) a variable?
If a variable has not been declared yet, you use the variable keyword, the variable name, and then initialize the variable with the assignment operator =
var fullName = ‘Brandon Moy’;
What characters are allowed in variable names?
Lowercase letters, uppercase letters (camel case), numbers, $, and _
Variables cannot start with numbers
What does it mean to say that variable names are “case sensitive”?
It means that the capitalization must be consistent across the entire variable
var Score is different from var score
What is the purpose of a string?
A string it used to record a data type that lets us store any types of characters
e.g. ‘Hello World!’
What is the purpose of a number?
A data type number is recorded to recall a number value (can be used for calculations or incrementation)
var width = 10; var height = 10;
What is the purpose of a boolean?
A boolean is used to define a value as true or false. It is used for decision making.
What does the = operator mean in JavaScript?
The = operator assigns the value on the right side to the variable on the left side
How do you update the value of a variable?
You can update a value of a variable by assigning it a new value further down the script
early: var fullName = ‘Brandon’;
later: fullName = ‘Brandon Moy’;
What is the difference between null and undefined?
Both are empty values but for different purposes. Null is a nonexistent or invalid object (cannot be used by JavaScript [can be used as a placeholder as null can ONLY be assigned]) whereas undefined is returned by JavaScript when there is no value assigned
Null - used by programmers to show empty
Undefined - JavaScript’s way to show empty
Why is it a good habit to include “labels” when you log values to the browser console?
Labels print information on the values being logged to the console for more ease of readability
Give five examples of JavaScript primitives.
String, Numbers, Boolean, Null, Undefined
What data type is returned by an arithmetic operation?
A number data type is returned by an arithmetic operation. If a string is put through an arithmetic operation JavaScript will print back NaN (not a number)
What is string concatenation?
String concatenation is when two or more strings are combined together to create a new string.
‘Hello’ + ‘ ‘ + ‘World!’ will return as ‘Hello World!’
What purpose(s) does the + plus operator serve in JavaScript?
The + operator can be used as arithmetic operator or string concatenator
What data type is returned by comparing two values (<, >, ===, etc)?
When comparing two values a boolean is returned for the value of the comparison
What does the += “plus-equals” operator do?
The += operator adds the new value to the starting variable and then assigns this new combined value back to the variable.
What are objects used for?
Objects are used to store multiple pieces of information into location without affecting other data and multiple pieces of information into one location to call back to.
What are object properties?
Object properties are just variables assigned to one object
var objectName = { property: propertyValue };
Describe object literal notation.
You use the variable keyword, the variable name, and you assign a grouping of properties to it inside of { }. Each property is notated property: value and a comma is used to separate the properties.
var objectName = {
property: value,
property2: value
};
How do you remove a property from an object?
delete operator is used to remove a property
delete object.property;
What are the two ways to get or update the value of a property?
Dot notation - object.property = newValue;
Square bracket - object[‘property’] = newValue;
What are arrays used for?
Arrays are used for storing a list of data. e.g. List of students, colors, hotels, cars