By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,377 Members | 1,688 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,377 IT Pros & Developers. It's quick & easy.

Function assigned to var wants extra semicolon

P: n/a
According to a JavaScript debugger (Firebug), and to a JS lint, this is
fine:

function recalc(){deriv = 6;} [more code here]

But, if I've assigned the function to a variable like this:

var bells = function recalc(){deriv = 6;} [more code here]

.... then both the debugger and the lint report an error, saying there's
a missing semicolon after the close-curly-brace. They say I should do
this:

var bells = function recalc(){deriv = 6;}; [more code here]

They must be right, because the code works the second way but not the
first way. But why? Isn't a close-curly-brace supposed to be sufficient
to indicate the end of a statement? Usually, if you put a semicolon
after a close-curly-brace like this:

function recalc(){deriv = 6;}; [more code here]

....the lint complains "Warning: empty*statement or*extra*semicolon".
But if the beginning of the statement includes a variable assignment,
it wants the extra semicolon at the end. Why?

--
Lawrence San
Cartoon Stories for Thoughtful People:
<http://www.sanstudio.com>
Oct 18 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Lee
Lawrence San said:
>
According to a JavaScript debugger (Firebug), and to a JS lint, this is
fine:

function recalc(){deriv = 6;} [more code here]

But, if I've assigned the function to a variable like this:

var bells = function recalc(){deriv = 6;} [more code here]

... then both the debugger and the lint report an error, saying there's
a missing semicolon after the close-curly-brace. They say I should do
this:

var bells = function recalc(){deriv = 6;}; [more code here]

They must be right, because the code works the second way but not the
first way. But why? Isn't a close-curly-brace supposed to be sufficient
to indicate the end of a statement? Usually, if you put a semicolon
after a close-curly-brace like this:

function recalc(){deriv = 6;}; [more code here]

...the lint complains "Warning: empty statement or extra semicolon".
But if the beginning of the statement includes a variable assignment,
it wants the extra semicolon at the end. Why?
One is a function definition, which logically ends with a closing bracket.
The other is an assignment statement.
The fact that what you have on the right-hand side of this
assignment happens to be a function definition doesn't change that.
--

Oct 18 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.