unit 4 Flashcards
what is a variable?
container for storing value
what does the computer do once a variable is created?
stores it in memory
what is the code for a variable?
var + label
when should we use var?
to change its value
where are the positions of the label and value?
label left, value right
initializing the varable
creating and assigning variable value right away
var lives = 3;
initializing the variable
creating and assigning variable value right away
var lives = 3;
what does ‘=’ mean?
gets the value
how do you use a variable?
refer it by its label
how can you see the value of a variable?
by using console.log as we can’t visually see it
what is the difference between writing the variable’s label with quotations and without?
with - refers to the name itself
without - refers to the value
if a variable is not declared what happens?
the program does not know what it is and an error occurs
example of variables in expression
var score = 3;
var newScore;
newScore = score + 1
what is different with variables when you use expressions?
you don’t assign a value directly
how much a computer determine an expression
use the current value and manipulate it (add, subtract etc) the way the expression wants it to
computer picks apart the expression