Javascript Flashcards
What is the purpose of variables?
To store data
How do you declare a variable?
Keyword var/let/const + name of variable
How do you initialize (assign a value to) a variable?
Using the assignment operator. (=)
What characters are allowed in variable names?
letters , numbers, $ dollar sign, _ underscore
What does it mean to say that variable names are “case sensitive”?
A variable starting with a lowercase and a variable starting with an uppercase will create two separate variables.
What is the purpose of a string?
Hold data type consisting of letters/ other characters. Any type of text content.
What is the purpose of a number?
Hold any data type handling numbers/numeric values. Counting, calculating sums, determining size, moving the position, setting time, etc.
What is the purpose of a boolean?
To hold data types of true or false.
What does the = operator mean in JavaScript?
Assign a value to the variable, also used to update the value given to a variable.
How do you update the value of a variable?
- Using the assignment operator.
- Do not need to use ‘var’ again, just the name and (=)
What is the difference between null and undefined?
- Null represents a placeholder value, might hold value in the future.
- Undefined is a value that has not been thought of yet, does not hold value yet.
Why is it a good habit to include “labels” when you log values to the browser console?
To help debug. It makes it clearer which variables are being logged and in which order.
Give five examples of JavaScript primitives.
String, number, boolean, undefined, null
What data type is returned by an arithmetic operation?
A numerical value
What is string concatenation?
The joining of two or more strings using (+) to create a new string
What is string concatenation?
The joining of two or more strings using (+) to create a new string
What purpose(s) does the + plus operator serve in JavaScript?
- This will combine the value of the string before and after the (+) operator (a concatenated string)
- Addition for numerical numbers.
What data type is returned by comparing two values (<, >, ===, etc)?
True/False
What does the += “plus-equals” operator do?
This will add the number value on the right and assigns the result to the variable
What are objects used for?
To group together a set of variables and functions to create a model.
What are object properties?
Variables that are part of an object.
Describe object literal notation.
The object is in curly braces with its contents, then stored in a variable. Each key is separated from its value using a colon and each property and method is separated with a comma.
Var (varName) = { property: ‘string’, };
How do you remove a property from an object?
- Use keyword delete then dot notation to identify the property or method you want to remove from the object.
- Delete var.varName;
What are the two ways to get or update the value of a property?
Using square brackets or dot notation.
Bracket:
varName[‘newString’] = ‘updatedVal’;
Dot: varName.newString = updatedVal;