473,396 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Function assigned to var wants extra semicolon

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
1 2137
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
4
by: Andrew V. Romero | last post by:
I have been working on a function which makes it easier for me to pull variables from the URL. So far I have: <script language="JavaScript"> var variablesInUrl; var vArray = new Array(); ...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
8
by: Falc2199 | last post by:
Hi, Does anyone know how to make this work? var sectionId = 5; repeat_section_sectionId(); function repeat_section_5(){ alert("firing"); }
7
by: Jimakos Bilakis | last post by:
Hi guys! I'm using the C++ Builder 6 Enterprise Edition where I create some tables in Paradox and with the help of a structure i pass my data from the form (Edit boxes) to the Paradox table with...
16
by: mdh | last post by:
May I ask the group the following: (Again, alas , from K&R) This is part of a function: while ( ( array1 = array2 ) != '\0' ); /* etc etc */ Is this the order that this is evaluated? ...
4
by: alex | last post by:
I am so confused with these three concept,who can explained it?thanks so much? e.g. var f= new Function("x", "y", "return x * y"); function f(x,y){ return x*y } var f=function(x,y){
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
2
by: phpentrylevel | last post by:
hello i am a newbie to Javascript with a in depth background of PHP i have a simple script that replaces missing images when the webpage loads but i just cant get it to validate in JLint as my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.