Quick Index
See new examples here...

Overview


Here is some discussion on the concept of variables... that is a good basis for this discussion.

We'll talk about primitive values here. We'll discuss objects soon.

Variables


We can declare variables in three different ways (const, let, var):

KeywordExample DeclarationUsage
constconst z = 5;When var will be constant (only set once)
letlet a, b;When var will be set multiple times
varvar a, b;Older style, it is recommended to use the above two only


Primitive Data Types


For a quick concept review go here

Number Example
NOTE WELL -- we're just playing here -- normally we would not be hard-coding values like the 7 and 2 -- there are exceptions (per usual) -- one could be test code.
		const
			a = 7,
			b = 2;
		let sum, sumSquared;
		sum = a + b;
		sumSquared = sum * sum;
		prn("sum: " + sum);
		prn("sumSquared: " + sumSquared);
Adding a string variable.
NOTE WELL -- we're just playing here -- normally we would not be hard-coding values like the 7 and 2 -- there are exceptions (per usual) -- one could be test code.
		const
			a = 7,
			b = 2,
			label1 = 'sum: ',
			label2 = 'sumSquared: ';
		let sum, sumSquared;
		sum = a + b;
		sumSquared = sum * sum;
		prn(label1 + sum);
		prn(label2 + sumSquared);