var myName = "Kieran";. But did you know you can declare more than one at a time using a single
Let's say I wanted to declare my name and my dog's name at the same time.
Instead of doing this:
var myName = "Kieran";
var dogName = "Yoko";
I could just do this:
var myName = "Kieran", dogName = "Yoko";
The only trouble is, it can cause some confusion.
It's possible to declare variables without initializing them; for example, I could declare
var myName;. That would create the variable without assigning it a value, so it would just be
undefined. I could then assign a value to it later on in the script.
That's fine, but when I've taken it a step further and written things like the following, it's confused other developers:
var myName, dogName = "Yoko";
This is because, in my opinion, it looks like I'm assigning the same value to both
dogName. In reality, I'm declaring
myName without assigning it a value (so it's
undefined) while assigning the string
Just something to be aware of in case you see it in the wild!