JAVASCRIPT Flashcards
(116 cards)
What is the purpose of variables?
to store data (short-term memory)
it can change or vary each time a script runs
How do you declare a variable?
var keyword var name;
ex: var quantity;
Var (old school), const, and let (if it’ll change)
How do you initialize (assign a value to) a variable?
quantity = 3;
What characters are allowed in variable names?
Upper or lowercase letter, dollar sign, or underscore
you can use numbers, but not as the first character
What does it mean to say that variable names are “case sensitive”?
if it is capitalized, you need to capitalize it always in order for it to be recognized as the same variable
What is the purpose of a string?
to store text (always within quotation marks) – letters and other characters
What is the purpose of a number?
counting, math, representing quantities, etc
- determining size of screen
- moving position of element on a page
- setting amount of time an element should take to fade in
What is the purpose of a boolean?
true/false values
What does the = operator mean in JavaScript?
It’s an assignment operator, not an ‘equal to’
How do you update the value of a variable?
use the equal sign. make sure it comes after the initial declaration
Why is it a good habit to include “labels” when you log values to the browser console?
it makes it clearer what variable is being logged and in what order
Give five examples of JavaScript primitives.
string number boolean null undefined symbol
What data type is returned by an arithmetic operation?
number
What is string concatenation?
combines separate strings together to form one string
What purpose(s) does the + plus operator serve in JavaScript?
to add one value to another
concatenates
What data type is returned by comparing two values (, ===, etc)?
boolean (true or false)
What does the += “plus-equals” operator do?
it’s a shorthand for the addition assignment
if you know you are going to take the sum and add to it, you can use this
instead of x = x + y, it becomes x += y
What are objects used for?
group together a set of variables and functions to create a model of something
ex: object is hotel
What are object properties?
variables
ex:
- name:
- rooms:
- booked:
Describe object literal notation.
var object = { key: value, key: value, method; }
each is separated with a comma, except for the last one
How do you remove a property from an object?
delete object.property;
to clear the value:
object.property = ‘’;
What are the two ways to get or update the value of a property?
dot notation
object.property = new value;
brackets notation
object[‘property’].= new value
What are arrays used for?
working with a list or set of values that are related to each other. especially when you don’t know how many items/values there will be
Describe array literal notation.
var arrayName;
arrayName = [‘value’, ‘value];
var color = arrayName[0]