JavaScript Flashcards
What is the purpose of variables?
hold on to data for the future
How do you declare a variable?
var (var is the keyword)
How do you initialize (assign a value to) a variable?
=
What characters are allowed in variable names?
The name must begin with
a letter, dollar sign ($),or an
underscore (_). It must not start
with a number. You cannot use keywords or reserved words.
What does it mean to say that variable names are “case sensitive”?
All variables are case sensitive,
so score and Score would be
different variable names, but
it is bad practice to create two
variables that have the same
name using different cases.
What is the purpose of a string?
hold a sequence of characters
What is the purpose of a number?
store numbers for calculations
What is the purpose of a boolean?
Booleans are helpful when
determining which part of a
script should run.
“make a choice”
What does the = operator mean in JavaScript?
assignment
How do you update the value of a variable?
You just use the
variable name, the equals sign
(also known as the assignment
operator), and the new value for
that attribute.
What is the difference between null and undefined?
null= can only be assigned (is/was actually assigned on purpose) 1. i’ll get data later 2. i’ll never get it but need to show you
undefined is a primitive value automatically assigned to variables that have just been declared, or to formal arguments for which there are no actual arguments. (javascript says “i never received it”
Why is it a good habit to include “labels” when you log values to the browser console?
if you do not include “labels”, it can be very confusing instead of helpful. A console log “label” is simply a short string that describes the variable or value being logged.
Since the console.log() method can write multiple values to the console at the same time, it’s easy to include a “label” when printing a value.
Give five examples of JavaScript primitives.
string.
number.
bigint.
boolean.
undefined.
symbol.
null.
console.log(‘value of fullName:’, fullName);
log method of the console object is being called with 2 arguments, the string ‘value of fullname’ and the variable fullName.
var fullName = ‘Cody Miller’
string cody miller is being assigned to the variable fullName
console.log(‘typeof fullName:’, typeof fullName);
log method of the console object is being called with 2 arguments, the string typeof full name and th result of typeof fullname
var never;
variable never is being declared but never assigned a value
What data type is returned by an arithmetic operation?
basic math
What is string concatenation?
two or more strings to create 1 string
What purpose(s) does the + plus operator serve in JavaScript?
adds one value to another and concatenate
What data type is returned by comparing two values (<, >, ===, etc)?
boolean
What does the += “plus-equals” operator do?
adds
motto += ‘ is the GOAT”
the value of the variable motto is being concatenated with the string ‘ is the goat’ and the result is being assigned to the variable motto
What are objects used for?
Objects group together a set of variables and functions to create a model of a something
What are object properties?
IN AN OBJECT: VARIABLES BECOME KNOWN AS PROPERTIES
Describe object literal notation.
object stored in a variable (optional),
content separates each key from its value inside curly braces
How do you remove a property from an object?
delete
What are the two ways to get or update the value of a property?
dot notation hotel.name = ‘park’;
bracket notation hotel[‘name’] = ‘park’
var student = {
firstname: Luke
lastname: skywalker
age: 25
};
object literal assigned to variable student
string luke assigned to variable firstname
code reading
. === “of”
[] === at
right of .
left of .
property
object
What are arrays used for?
whenever you are working
with a list or a set of values that
are related to each other.
Arrays are especially helpful
when you do not know how
many items a list will contain
where order is either important or not important
Describe array literal notation.
The values are assigned to the
array inside a pair of square
brackets, and each value is
separated by a comma. The
values in the array do not need
to be the same data type, so you
can store a string, a number and
a Boolean all in the same array.
How are arrays different from “plain” objects?
object = order of properties not important
array= index numbers dictate order of properties, has length