My JavaScript tutorials are like your best friend walking you through tough times - real nice and easy-like. None of that eye-glazing technobabble. Visit howtocodejs.com to start learning.
That's a good question. For one, the concept of hoisting doesn't seem to be something people write their programs around. It's a convenient side-effect that some don't even recognize.
The thing about initialization versus declaration comes down to convention and flexibility.
It is the convention to create a class with a function declaration:
function Bat{...}
But if I wanted to create a function prototype, I would use an assignment operator.
Bat.prototype.fly = function(){...}
Because functions are first order, I can assign them, return them, use them as parameters.
Whether to declare or assign might just come down to style for some, but the differences go beyond hoisting.
I was thinking in terms of assigning to variables, but thanks for pointing out those other ways of assigning. I don't normally think of it that way with prototype methods and callbacks, but that does make sense.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
That's a good question. For one, the concept of hoisting doesn't seem to be something people write their programs around. It's a convenient side-effect that some don't even recognize.
The thing about initialization versus declaration comes down to convention and flexibility.
It is the convention to create a class with a function declaration:
function Bat{...}
But if I wanted to create a function prototype, I would use an assignment operator.
Bat.prototype.fly = function(){...}
Because functions are first order, I can assign them, return them, use them as parameters.
Whether to declare or assign might just come down to style for some, but the differences go beyond hoisting.
I was thinking in terms of assigning to variables, but thanks for pointing out those other ways of assigning. I don't normally think of it that way with prototype methods and callbacks, but that does make sense.