Scripter Javascript Tutorial
javascriptmusiclogicscripterbookexcerpttutorial11 Variables
MDN: Grammar and types: Declarations
A variable is a kind of named storage for any kind of data.
12 var
and
let
MDN:
Variables are typically declared with the var
keyword to
make clear something is a new variable.
var tonic = 60;
var controlName = "Tonic";
In the above example:
Line 1 shows a variable
tonic
is declared and is assigned with the=
sign the value of60
.Line 2 is very similar: a variable named
controlName
is declared and assigned the value of “Tonic
”.
Modern JavaScript also uses the let
keyword, which
Scripter supports. The below example has the exact outcome as using
var
.
let tonic = 60;
let controlName = "Tonic";
In both cases of var
and let
, variables can
be assigned new values by leaving off the var
and
let
keywords:
var tonic = 60;
let controlName = "Tonic";
= 72;
tonic = "Range"; controlName
All of the examples in this book will use var
to declare
variables.