01 / 05
The basics of syntax
INPUT · Slides
Meet the variable
02 / 05
Make one with let
To make a variable you write let, then the name, then =, then the value you want in it.
= does not mean "is equal to" here. It means "put the thing on the right into the thing on the left". That is different from the = in your maths book, so watch out.
let name = "Yui";console.log(name);Result
Yui
03 / 05
Write the name and out comes what is inside
To use a variable you just write its name. No " around it.
Wrap it and you get "the word name" instead, and what is inside never comes out.
let city = "Tokyo";console.log(city);console.log("city");Result
Tokyo city
04 / 05
Numbers go in too
Strings are not the only thing a variable will hold. A number goes in just as happily, and once it is in there you can do maths with it.
let price = 150;console.log(price * 2);Result
300
05 / 05
Choosing a name
You get to pick the name, but there are rules and there are habits.
- You may use letters, digits,
_and$. It must not start with a digit - Pick a name that says what is inside (
pricebeatsa) - If it takes two words, the habit is to capitalise the second one, as in
userName