Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When I tried without ; the server shows error.
Why is it most necessary so that function doesn't call without semicolon

Consider I am having javascript code as
function myfunction(){
// code part
}



<asp:RadioButtonList ID="rblistGender" runat="server" onclick="myfunction();">


Why the semicolon at the onclick method is needed?

I have to execute my code whenever the user changes the value of the radio button list.
Posted
Updated 19-Aug-15 4:02am
v3
Comments
Which function and from where? Please put some code.
CHill60 19-Aug-15 9:16am    
And the text of the error!

1 solution

Why do you end sentences with a period and start them with a capital letter? So we know when your sentences begin and end. Same reason that js likes to see a semi-colon, it tells it this is the final statement. I think a lot of js implementations don't require the ; but it is most important when it comes to things that start code segments.

if (x == 1)
   x = x + 1;


The above means increment x if x is 1.

if (x == 1);
   x = x + 1;


The above means that if x is 1 do nothing. Then always increment x.

As best practice you should always use them.
 
Share this answer
 
Comments
[no name] 19-Apr-24 10:30am    
hey why is it my answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900