I'm refreshing my JS knowledge by doing a JS course. There's something about variables that have left me a little confused.
var variableVar = 'This is a variable pre ES6'; // var
let variableLet = 'This is a variable that can be changed'; // let
const variableConst = 'This variable cannot be changed'; // con
alsoWorks = 'This also works'; // What's this?
console.log(variableVar);
console.log(variableLet);
console.log(variableConst);
console.log(alsoWorks);
I understand var, const and let. I also noticed I don't need to declare any of these for a variable to work e.g. alsoWorks = 'This also works';
. Why shouldn't I write a variable like this?