JavaScript Flashcards
(188 cards)
What is the purpose of variables?
Represents and stores the values in our data
How do you declare a variable?
By using var, let, or const before naming the variable
Ex. var variableName
How do you initialize (assign a value to) a variable?
By using var to declare our variable, then an equal sign, and then our value
What characters are allowed in variable names?
$, letters, numbers, underscore
What does it mean to say that variable names are “case sensitive”?
A capital A is not the same as a lowercase a. Uppercase and lowercase letters are different values in JS.
What is the purpose of a string?
Allows us to store and manipulate text
What is the purpose of a number?
Allows us to calculate sums, count, and perform other tasks (i.e determining size, moving position of an element, etc.)
What is the purpose of a boolean?
Gives us a true or false value that tells our program which script to run
What does the = operator mean in JavaScript?
This is the assignment operator. It assigns the value on the right to the variable on the left
How do you update the value of a variable?
Put the variable on a new line with a different value assigned to it
What is the difference between null and undefined?
Null - an intentional absence of a value
Cannot be created by javascript only by humans
Undefined - accident; no one plans for this to have a value
Why is it a good habit to include “labels” when you log values to the browser console?
The console does not log the variable name in the output so it is good practice to include it ourselves so that we see what the purpose of our value is (helps other people understand your data as well)
Give five examples of JavaScript primitives.
Undefined , null , boolean , string and number
What data type is returned by an arithmetic operation?
Numbers
What is string concatenation?
The process of adding two strings together to create a new string
What purpose(s) does the + plus operator serve in JavaScript?
Addition - math purposes
Concatenation - adding strings together
What data type is returned by comparing two values (, ===, etc)?
A boolean true or false
What does the += “plus-equals” operator do?
Adds the value of the right operand to a variable and assigns the result to the variable.
What are objects used for?
An object is a collection of properties, and a property is an association between a name (or key) and a value.
A data type that allows you to store and manipulate data.
What are object properties?
Object properties are variables/key that gives us information about an object
Describe object literal notation.
Var declaration, then we have the object, within the curly opening and closing curly brace we have the keys: which are the property names and its value & the method
How do you remove a property from an object?
By using the delete operator and then object.property
Ex. delete hotel.name;
What are the two ways to get or update the value of a property?
Dot notation
Put the object name with a dot and then assign the new variable on the right
Ex. hotel.name = ‘new value’
Square brackets
Ex. hotel[‘name’] = ‘new value’
What are arrays used for?
They are used to store a list of values