473,511 Members | 16,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

semicolon

Hi,
When I look through the "javascript bible" I don't find any example
scripts that have lines with ending semicolons. However when I peruse
this newsgroup I find that sometimes there are ending semicolons and
sometimes not.

Perhaps someone could enlighten me as to their proper usage in
javascript.

thank you

f.
Jul 23 '05 #1
11 1926


fritz wrote:

When I look through the "javascript bible" I don't find any example
scripts that have lines with ending semicolons. However when I peruse
this newsgroup I find that sometimes there are ending semicolons and
sometimes not.

Perhaps someone could enlighten me as to their proper usage in
javascript.


In JavaScript a semicolon terminates a statement, much the same as in
other C-like languages. However one of the scripting language like
features of JavaScript is an automatic semicolon insertion to free
scripters from having to write it explictly. Thus while in C or Java you
have to write

statement1;
statement2;

in JavaScript you are free to write

statement1
statement2

You should however be careful about statements like return or throw as
an automaticaly inserted semicolon can hurt you and change the meaning
of your script e.g. if you code
return
expression
then due to the rules of automatic semicolon insertion that is parsed as
return;
expression
and the return statement then does not return the result of evaluating
the expression but the value undefined.
The ECMAScript standard which standardizes the core JavaScript language
gives the following rules of practical advice to scripters to avoid
problems with automatically inserted semicolons:

• A postfix ++ or -- operator should appear on the same line as its operand.
• An Expression in a return or throw statement should start on the same
line as the return or
throw token.
• A label in a break or continue statement should be on the same line as
the break or
continue token.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
Martin Honnen wrote:
In JavaScript a semicolon terminates a statement, much the same as in
other C-like languages. However one of the scripting language like
features of JavaScript is an automatic semicolon insertion to free
scripters from having to write it explictly. Thus while in C or Java you
have to write

statement1;
statement2;

in JavaScript you are free to write

statement1
statement2

You should however be careful about statements like return or throw as
an automaticaly inserted semicolon can hurt you and change the meaning
of your script e.g. if you code
return
expression
then due to the rules of automatic semicolon insertion that is parsed as
return;
expression
and the return statement then does not return the result of evaluating
the expression but the value undefined.
The ECMAScript standard which standardizes the core JavaScript language
gives the following rules of practical advice to scripters to avoid
problems with automatically inserted semicolons:

• A postfix ++ or -- operator should appear on the same line as its
operand.
• An Expression in a return or throw statement should start on the same
line as the return or
throw token.
• A label in a break or continue statement should be on the same line as
the break or
continue token.

Thank you very much Martin! I just downloaded the ECMAScript262 and
will have a go at it. I take it then that terminating each line is up to
the writer and doing it makes no difference in the long run except for
things like 'return' or break. So if the language sees an ending ';' it
doesn't add another.

BTW, I googled on 'javascript IDE' and came up with not too much
but a few references back in 2000. Has anyone tried to take javascript
up to a general purpose language such as perl?

f.
Jul 23 '05 #3


fritz wrote:
Has anyone tried to take javascript up to
a general purpose language such as perl?


J(ava)Script is being used in other environments as the browser, on
Windows you can use it for automation with Windows Script Host and for
server side scripting within ASP pages.
Another example of automation using JavaScript is <http://www.jsdb.org/>.

While those uses don't make JavaScript a general purpose programming
language it certainly shows that the language is being used outside of
the browser.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #4
fritz wrote:
Hi,
When I look through the "javascript bible" I don't find any example
scripts that have lines with ending semicolons. However when I peruse
this newsgroup I find that sometimes there are ending semicolons and
sometimes not.

Perhaps someone could enlighten me as to their proper usage in
javascript.

thank you

f.

I found the advise about when to use/not use semicolons very confusing
as well. I now run all my code through JSLint which has a much stricter
set of coding rules than the Javascript language. JSLint demands that
you always use semicolons. You can read about it here:
http://www.crockford.com/javascript/lint.html

If you are a Mozilla Firefox user, another under-utilized tool is JS
Console that installs as a Firefox extension. JS Console is a
development tool for writing complex Javascript routines. It encourages
you to follow the principles of Extreme Programming -- you write a
simple test to prove your code works, then you write enough code to pass
the test, then you write a more complex test, then you write enough code
to pass the test... repeating the process until you have working code.
You can read more about it here:
http://jsconsole.mozdev.org/

Both of the above will require some study before you will understand how
to use them. They are good tools and well worth the effort.

Roger

Jul 23 '05 #5
Roger wrote:
I found the advise about when to use/not use semicolons very confusing
as well. I now run all my code through JSLint which has a much stricter
set of coding rules than the Javascript language. JSLint demands that
you always use semicolons. You can read about it here:
http://www.crockford.com/javascript/lint.html
I just visited the site and I will study it carefully in the next few days.

If you are a Mozilla Firefox user, another under-utilized tool is JS
Console that installs as a Firefox extension. JS Console is a
development tool for writing complex Javascript routines. It encourages
you to follow the principles of Extreme Programming -- you write a
simple test to prove your code works, then you write enough code to pass
the test, then you write a more complex test, then you write enough code
to pass the test... repeating the process until you have working code.
You can read more about it here:
http://jsconsole.mozdev.org/

As a matter of fact I do use the firefox browser as the primary. I see
it under the tools menu. I just clicked upon it and found that it gives
quite a lot of information. However, I didn't install it and it isn't
listed under the extensions but there it is. Now to gradually use it also.
Both of the above will require some study before you will understand how
to use them. They are good tools and well worth the effort.

Roger

Thank you so much Roger. It is nice to be able to ask for help and get
such competent answers. I will try to do as you and others have suggested.

f.
Jul 23 '05 #6
Martin Honnen wrote:

J(ava)Script is being used in other environments as the browser, on
Windows you can use it for automation with Windows Script Host and for
server side scripting within ASP pages.
Another example of automation using JavaScript is <http://www.jsdb.org/>.

While those uses don't make JavaScript a general purpose programming
language it certainly shows that the language is being used outside of
the browser.

I just took a look at the link jsdb. I am always amazed at how someone
could do what he has done.
Also, looked up ASP and it looks like that is something that someone
referred to in a previous post:

*********************
Mr. Oz wrote:
The type of script that you are suggesting is often run at the server to
ensure that what is sent to the user is HTML and has no client-side
dependencies outside support for stated the DOCTYPE.
*******************

In other words using ASP scripting to assemble the page prior to sending
it since the client may have JS turned off? Since ASP takes VBScript or
JavaScript does it have to run on Windows servers or can one run it on any?

thanks

f.
Jul 23 '05 #7
Roger wrote:
I found the advise about when to use/not use semicolons very confusing
as well. I now run all my code through JSLint which has a much stricter
set of coding rules than the Javascript language. JSLint demands that
you always use semicolons. You can read about it here:
http://www.crockford.com/javascript/lint.html

If you are a Mozilla Firefox user, another under-utilized tool is JS
Console that installs as a Firefox extension. JS Console is a
development tool for writing complex Javascript routines. It encourages
you to follow the principles of Extreme Programming -- you write a
simple test to prove your code works, then you write enough code to pass
the test, then you write a more complex test, then you write enough code
to pass the test... repeating the process until you have working code.
You can read more about it here:
http://jsconsole.mozdev.org/

Both of the above will require some study before you will understand how
to use them. They are good tools and well worth the effort.

Roger

It looks like my response to your post didn't make the grade. Blank.
Anyway I downloaded the JSLint and in a few days after making my small
code work properly I'll submit to it.

AS to the JSConsole it appears to be installed in my firefox which I
do use as the primary browser. I will use it from now on. It had a fit
when I showed it a rather popular internet site. :-)

Thanks

f.
Jul 23 '05 #8
fritz wrote:
In other words using ASP scripting to assemble the page prior to sending
it since the client may have JS turned off?
It is a good idea to use client-side JavaScript only for optional
enhancements (i.e. things that the user can live without) that degrade
gracefully.

ASP is one option, although not my first choice, for generating content
pragmatically before presenting it to the user.
Since ASP takes VBScript or JavaScript does it have to run on Windows
servers or can one run it on any?


As well as VBScript and JScript, you can use PerlScript with ASP. There are
probably other languages available for it too, but my experience with it
isn't that great.

ASP can be used on non-windows platforms, but the languages you can use with
it will probably vary (and you won't be able to use Windows specific
components).

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 23 '05 #9
fritz wrote:
Roger wrote:
> I found the advise about when to use/not use semicolons very confusing

as well. I now run all my code through JSLint which has a much
stricter set of coding rules than the Javascript language. JSLint
demands that you always use semicolons. You can read about it here:
http://www.crockford.com/javascript/lint.html

If you are a Mozilla Firefox user, another under-utilized tool is JS
Console that installs as a Firefox extension. JS Console is a
development tool for writing complex Javascript routines. It
encourages you to follow the principles of Extreme Programming -- you
write a simple test to prove your code works, then you write enough
code to pass the test, then you write a more complex test, then you
write enough code to pass the test... repeating the process until you
have working code. You can read more about it here:
http://jsconsole.mozdev.org/

Both of the above will require some study before you will understand
how to use them. They are good tools and well worth the effort.

Roger

It looks like my response to your post didn't make the grade. Blank.
Anyway I downloaded the JSLint and in a few days after making my small
code work properly I'll submit to it.

AS to the JSConsole it appears to be installed in my firefox which I
do use as the primary browser. I will use it from now on. It had a fit
when I showed it a rather popular internet site. :-)

Thanks

f.


You probably have "Javascript Console" installed on Firefox, which is
different from JS Console. "Javascript Console" is pretty handy as well
and tells you about errors you have on the current web page. "Javascript
Console" is installed by default.

"JS Console" is not installed by default, you have to install it
yourself. JS Console does not know about web pages, it is a heavy duty
development tool for writing complex Javascript procedures.

Since the thread is now about Firefox, there is yet another great
extension for validating your HTML code. It is called the Firefox HTML
Validator. You can read about it at:

https://addons.update.mozilla.org/ex...cation=firefox

Roger

Jul 23 '05 #10
David Dorward wrote:
fritz wrote:

In other words using ASP scripting to assemble the page prior to sending
it since the client may have JS turned off?

It is a good idea to use client-side JavaScript only for optional
enhancements (i.e. things that the user can live without) that degrade
gracefully.

After all of the comments that I have gotten here, I think that my
course of action will be: Writing the menu and positioning with
javascript and css, and then only after all is working well, start the
exploration of the other ways of doing it.
ASP is one option, although not my first choice, for generating content
pragmatically before presenting it to the user.

Since ASP takes VBScript or JavaScript does it have to run on Windows
servers or can one run it on any?

As well as VBScript and JScript, you can use PerlScript with ASP. There are
probably other languages available for it too, but my experience with it
isn't that great.

ASP can be used on non-windows platforms, but the languages you can use with
it will probably vary (and you won't be able to use Windows specific
components).

Thank you for the comments Mr. Dorward! I peeked at your site and
now I have more tutorials to go through ;-) Where does the time go?
Thanks again.

f.
Jul 23 '05 #11
Roger wrote:
probably have "Javascript Console" installed on Firefox, which is
different from JS Console. "Javascript Console" is pretty handy as well
and tells you about errors you have on the current web page. "Javascript
Console" is installed by default.

"JS Console" is not installed by default, you have to install it
yourself. JS Console does not know about web pages, it is a heavy duty
development tool for writing complex Javascript procedures.

Since the thread is now about Firefox, there is yet another great
extension for validating your HTML code. It is called the Firefox HTML
Validator. You can read about it at:

https://addons.update.mozilla.org/ex...cation=firefox
Roger

You are correct. It isn't installed. I'll go get it and the
validator and work with it!
f.
Jul 23 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
2312
by: subnet | last post by:
I'm not a C expert, but I've seen this topic discussed in the newsgroup several times. What's the deal with writing such programs? Why are they considered so interesting? Thanks
64
3305
by: Merrill & Michele | last post by:
#include <stdio.h> int main(void) { int i = 0; ++ i; ++ i; printf("i equals %d\n", i); return 0; } I've been trying to determine the great and manifold uses of the semicolon
3
4487
by: Dan | last post by:
I'm writing a record from an asp.net page to SQL Server. After the insert I'm selecting @@identity to return the ID of the record that I just wrote. It worked fine until I typed a semicolon into...
1
2142
by: Lawrence San | last post by:
According to a JavaScript debugger (Firebug), and to a JS lint, this is fine: function recalc(){deriv = 6;} But, if I've assigned the function to a variable like this: var bells =...
3
7081
by: Peter Michaux | last post by:
Hi, These first three links say that when reading document.cookie the name-value pairs are separated by semicolons and they show examples like "name=value;expires=date" where there is clearly...
3
5884
by: Ken | last post by:
Hi all, I want to printf a sentence with a semicolon, for examples: printf(" I like C language; You like C++ language."); But C compiler alway identify the semicolon as a end of a sentence and...
9
7323
by: David Trimboli | last post by:
On a couple of my pages http://www.trimboli.name/rune/goblinmagic.html http://www.trimboli.name/rune/labyrinth.html I've got a number of definition lists concerning "Points Spent" and "Points...
2
2271
by: kolla | last post by:
how to write a c programme to print a semicolon without writing using a semicolon in the main program
4
5647
by: liz0001 | last post by:
Hi, I am getting this error when I try to run my code: Missing semicolon (;) at end of SQL statement However, there is a semicolon at the end of my statement. Here is the statement: INSERT...
0
7138
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
7355
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,...
1
7081
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7510
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...
1
5066
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1576
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
447
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.