CoffeeScript variable initialization: Why?

coffeescript, javascript, variables

Solution

coffeescript compiles to jslint-conform javascript, and puts all variable declarations to the top of the current scope/function.

Problem

I've been playing with CoffeeScript, and I've used js2coffee to experiment. One thing I noticed was the way CoffeeScript handles variable initialization. This CoffeeScript: `string = 'word'` compiles to this JavaScript: ``` var string; string = 'word'; ``` What is the advantage of the `var string;` declaration? Why not `var string = 'word';`

Original source