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