New FAQ Version for review

J

John G Harris

Dr J R said:
In comp.lang.javascript message


Perhaps. But first you have to tell me what they, in your opinion,
are, and I have to agree with you or at least believe you.

Here is what I would have written. You'll notice that some of my
assertions differ from some of yours.


===========================================================
Identifiers

Identifiers give names to variables, functions, and
properties so that the compiler knows which one you're
talking about.

With some restrictions, an identifier is any combination of
letters, digits, '_', and '$' characters. Unicode letters
and a few obscure Unicode symbols are allowed. Identifiers
are case sensitive.

One restriction is that an identifier does not start with a
decimal digit, ('0' to '9'). The other restriction is that
an identifier is not one of the javascript keywords, (while,
var, in, ...), nor one of the words reserved for future use,
(class, goto, ...), nor one of the words null, true, false.

It is best not to use '$' as it makes identifiers difficult
to read and is there for use by programs that write
javascript programs.


Variables

It is better to declare each variable explicitly, as in
var x;

If this is done inside a function then x becomes a local
variable, different from any global variable and any
local variable named x in other functions. It is also
different from the local variable named x in a recursive
call of the same function.


===========================================================
Semicolons

Some statements end with a semicolon, ';'; some end with a
close curly brackets, '}'; all other statements end with a
nested, simpler, statement. Here is an example that shows
all three cases :
if (x==0)
{ y = 0; z = 1; }
The 'if' statement ends with a block statement, { ... }.
The block statement ends with a close curly brackets. Each
of the two statements inside the block statement ends with
a semicolon.

A 'var' declaration is classified as a statement. It ends
with a semicolon.

A 'function' declaration is not classified as a statement,
though it looks much the same. It ends with a close curly
brackets.

In some cases you need not write the semicolons yourself.
In effect, the compiler will write them for you. One case
is when the semicolon is at the end of the line *and* the
beginning of the next line cannot possibly be part of the
same statement. The other case is when the semicolon is
followed by a close curly brackets. (Ignore comments when
applying these rules). Thus the example can be written as :
if (x==0)
{ y = 0
z = 1 }

In return for being able to leave out some of the
semicolons you must be careful where you put your line
endings. In particular, if a function returns a value then
the expression giving the value must start on the same line
as the 'return' keyword.

The semicolons inside a 'for' condition, (... ; ... ; ...),
cannot be omitted.

The full rules are given in ECMA 262.

===========================================================


John
 
D

Dr J R Stockton

In comp.lang.javascript message
Sun said:
Here is what I would have written. You'll notice that some of my
assertions differ from some of yours.

You're writing a simplified manual; I'm writing remarks aimed at those
who have already read as much manual or specification as they want to
(want != need).

For example, you're saying what can be used as an identifier; I'm
indicating what should be used : 'it' is a perfectly good identifier to
the parser; but it's not a good choice for a programmer/coder, as it's
difficult to search a set of pages for 'it' without getting swamped by
instances in strings, comment, and HTML-marked text.
===========================================================
Identifiers

Identifiers give names to variables, functions, and
properties so that the compiler knows which one you're

I'd not think "compiler" appropriate, "parser" seems better.
 
J

John G Harris

Dr J R said:
In comp.lang.javascript message <[email protected].
nospam.invalid>, Sun, 10 Dec 2006 13:28:57, John G Harris

Given that you understand this, I'm surprised you didn't notice the
mistake in
"Every identifier used within a function
should be declared as a var" ... .

I'd not think "compiler" appropriate, "parser" seems better.

A parser just builds parse trees. In other languages, finding out the
meaning of each identifier is done somewhere else in the compiler, with
the parse trees as input.

As it happens, "compiler" is wrong for javascript. Finding out what an
identifier refers to is done at run-time, inside the program.

John
 
E

Evertjan.

John G Harris wrote on 11 dec 2006 in comp.lang.javascript:
As it happens, "compiler" is wrong for javascript. Finding out what an
identifier refers to is done at run-time, inside the program.

"Interpreter" is the name.

Well not quite.

In the old days, a compiler made a machine language [well not quite]
programme from the source code, that could be executed independently.

In the old days, an interpreter ran a source script while(!!!) it was
executing the script. A function could not be called if it was not defined
higher up in the script.

Nowadays, a script is first scanned by the "interpreter" at runtime(!!!),
before the real execution of some intermediate code, that is made in the
first scan by a process akin to compiling, starts.

At least, that is what I deduct from what they tell me!

Should we coin "javascript execution engine"?

I prefer "interpreter" or perhaps simply "javascript engine".
 
D

Dr J R Stockton

In comp.lang.javascript message
Mon said:
Given that you understand this, I'm surprised you didn't notice the
mistake in
"Every identifier used within a function
should be declared as a var" ... .

Eschew selective or inadequate quoting, ESPECIALLY when you're not
quoting the previous News article.

And remember that you were there reading a recommendation for the use of
the language, not a requirement of the language (likewise, the regulars
here agree on the benefit of indentation to show structure and of some
other non-essential whitespace; but the javascript engine does not need
it).
A parser just builds parse trees. In other languages, finding out the
meaning of each identifier is done somewhere else in the compiler, with
the parse trees as input.

Maybe "interpreter" or "javascript engine" for your text, then.
 
J

John G Harris

Evertjan. said:
John G Harris wrote on 11 dec 2006 in comp.lang.javascript:
As it happens, "compiler" is wrong for javascript. Finding out what an
identifier refers to is done at run-time, inside the program.

"Interpreter" is the name.

Well not quite.

In the old days, a compiler made a machine language [well not quite]
programme from the source code, that could be executed independently.

In the old days, an interpreter ran a source script while(!!!) it was
executing the script. A function could not be called if it was not defined
higher up in the script.

Nowadays, a script is first scanned by the "interpreter" at runtime(!!!),
before the real execution of some intermediate code, that is made in the
first scan by a process akin to compiling, starts.

At least, that is what I deduct from what they tell me!

Should we coin "javascript execution engine"?

I prefer "interpreter" or perhaps simply "javascript engine".

I vote for javascript engine. Then no-one gets confused by what
interpreters do or don't do in other languages.

Question : Is your program running in a computer simulated by the
engine, or is the engine running with your program as data ?

If the latter, then you never make programming errors because your
program never runs :)

John
 
E

Evertjan.

John G Harris wrote on 12 dec 2006 in comp.lang.javascript:
I vote for javascript engine. Then no-one gets confused by what
interpreters do or don't do in other languages.

Question : Is your program running in a computer simulated by the
engine, or is the engine running with your program as data ?

if it was simulated, there would be no effect.
If the latter, then you never make programming errors because your
program never runs :)

No, script programmes run "on" an engine.

"Water boils in a kettel,
so the water does not boil,
the kettel does"???

;-} ;-}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top