JavaScript Flashcards
What is the purpose of variables?
Variable is a container for a value, like a number we might use in a sum, or a string that we might use as a part of a sentence.
How do you declare a variable?
We type the keyword (var, let, const) followed by the name you want to call your variable.
How do you initialize (assign a value to) a variable?
First type the variable name, followed by the equals sign(=), followed by the value you want to give it.
Example: var firstName = ‘Dylan’;
What characters are allowed in variable names?
letters, numbers (cannot start with a number!) dollar sign($), or an underscore
What does it mean to say that variable names are “case sensitive”?
Variable names care about the case sensitivity of their names, meaning a variable named score and Score would be different because of the capitalization of the letter S in score.
What is the purpose of a string?
Strings are pieces of text, they must be wrapped within quote marks.
What is the purpose of a number?
calculating numbers, doing math stuff
What is the purpose of a boolean?
True or False values, they are generally used to test a condition, after which code is run as appropriate.
What does the = operator mean in JavaScript?
1 equal sign is used for assignment of variables
How do you update the value of a variable?
Once the variable has been initialized, you can change (or update) that value by giving it a different value.
What is the difference between null and undefined?
Null means empty can only be assigned, undefined means a variable is declared but has no actual arguments.
Why is it a good habit to include “labels” when you log values to the browser console?
A label in the console.log is a simple way to describe the variable or value being logged.
Give five examples of JavaScript primitives:
string, number, boolean, null, and undefined
What data type is returned by an arithmetic operation?
single numerical value (number)
What is string concatenation?
the process of appending one string to the end of another string and so on.
What purpose(s) does the + operator serve in JavaScript?
- addition in math
- string concatenation
What data type is returned by comparing two values (< , > , === . etc)?
boolean ( true or false )
What does += “plus equals” operator do?
+= or “plus-equals” adds the value of the right operand to a variable and assigns the result to the variable. The types of the two operands determine the behavior of the addition assignment operator.
What are objects used for?
It is used to store various keyed collections and more complex entities
What are object properties?
Properties are the values associated with a JavaScript object.
Describe the object literal notation:
The Object literal notation is basically an array of key:value pairs, with a colon separating the keys and values, and a comma after every key:value pair, except for the last, just like a regular array. Values created with anonymous functions are methods of your object.
How do you remove a property from an object?
delete operator
What are two ways to get or update the value of an object property?
dot notation and bracket notation
What are arrays used for?
Storing a collection of multiple items under a single variable name