JavaScript Flashcards
What is the purpose of variables?
Variables store data
How do you declare a variable?
Use the keyword var to create a variable and give it a name. Statement ends with a semicolon.
EX: var firstName;
How do you initialize (assign a value to) a variable?
Use the var key word to initialize a new variable. Use the = assignment operator to give the variable a value.
EX: var firstName = ‘Rachel’
What characters are allowed in variable names?
letters, numbers, dollar sign ($), or underscore (_).
What does it mean to say that variable names are “case sensitive”?
Use of capital and lower cases are important in the variable name. score and Score would be 2 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?
The strings data type consists of letters and other characters. Strings are useful when working with any kind of text.
What is the purpose of a number?
The numeric data type handles numbers.
For tasks that involve counting or calculating sums, you will use numbers 0-9.
What is the purpose of a boolean?
Boolean data types can have one of two values: true or false. Booleans are helpful when determining which part of a script should run.
what does the = operator mean in JavaScript?
the equals sign (=) is an assignment operator. It says that you are going to assign a value to the variable/ update the value given to a variable.
How do you update the value of a variable?
variableName = newValue
What is the difference between null and undefined?
Null means nothing, undefined means the value has not been set/assigned yet.
Why is it a good habit to include “labels” when you log values to the browser console?
A console log “label” is a short string that describes the variable or value being logged.
Give 5 examples of JavaScript primitives.
String, number, boolean, undefined, null.
What data type is returned by and arithmetic operation?
Number
What is string concatenation?
Joining of 2 or more strings by using + operator
what purpose(s) does the + operator serve in JavaScript?
Arithmetic addition, concatenating strings
what data type is returned by comparing two values ( < , > , = = = , etc)?
boolean - true or false
What does the += “plus-equals” operator do?
addition assignment
What are objects used for?
Objects are used to group together a set of variables and functions. Used to group related data together.
what are object properties?
Properties tell us about the object. Property is a key-value pair.
Describe object literal notation.
var objectName = {
property: value,
property: value,
};
How do you remove a property from an object?
Using the delete operator followed by objectName.propertyName OR objectName[“propertyName”]
What are the two ways to get or update the value of a property?
.notation OR
[“bracket notation”]. .notation is preferable for objects.
Bracket notation is used when the property name is not actually known (it’s in a variable or i needs o be calculated. Bracket notation is also required when the property key is not a valid identifier (variable name)
What are arrays used for?
To store a list or set of values that are related to each other in one variable.