Talk:JavaScript syntax
From Wikipedia, the free encyclopedia
Contents |
[edit] Inaccuracy (needs citation)
The following statement: "else statements must be cuddled (i.e. "} else {" , all on the same line), or else some browsers may not parse them correctly." found in section 5.1 is incorrect. I have been programming in javascript for 4 years, and have never used that programming style. I have yet to notice any browser incompatibilities. If this statement is true, please provide a citation. - Kickboy 04:07, 24 August 2006 (UTC)
[edit] Inheritance without prototyping, etc.
I removed that part because it isn't syntax, it isn't very useful or common in modern times, et cetera. That and the preceding section need some clarification, as it is long and some ground is covered multiple times, but I'm not up to that right now. Quamaretto 03:19, 20 February 2006 (UTC)
[edit] Biased views
I am a bit surprised about Quamaretto's behavior. He tends to throw away contributions that dont fit into his view of JavaScript. I am currently unsure if I should waste my time contributing to WikiPedia if it is so easy for others to impose their biased view upon others.
- As far as the most relevant sources are concerned, you were apparently right about the origin of the syntax regarding Java and other languages, and I left the original quote in the article. (The first time I removed your material, I assumed that you were trolling or didn't have a relevant source since you didn't present one. That change is my bad, I guess.)
- As far as the other material, you should see the article WP:NOR and others in WP:What Wikipedia is not. There are sound reasons for all of those. The language comparison section is original material you wrote to demonstrate your point—, which was plainly already demonstrated by the quote.
- Basically, I corrected your changes to present the relevant information you gave, as well as to preserve the stated rules of Wikipedia. There's no reason to get upset over that. Quamaretto 00:02, 28 April 2006 (UTC)
-
- Look at the large amounts of example code in the sections below. For example the assignment section. Is it really a good idea to present tons of scarcely commented examples to the reader ? Is it allowed to confront users with vast amounts of example code, but not allowed to explain to them that assignment and operators were taken over from C with almost no change ? Before presenting lots of boring examples, I wanted to give the reader a rough orientation scheme about what to expect.
-
- The second reason for listing up the origins of the syntax elements was to introduce the reader to the subject of JavaScript syntax. There was none.
-
- Another observation which leaves me speechless is that my introduction gets thrown away, while other commercial artifacts are kept. Look at the third paragraph of the JavaScript page. Look at the two links at the end of the paragraph. Link 2 may be justified (Sun Trademarks), but link 1 points to an unrelated Copyright page at SAP. This looks like commercial subversion to me. But maybe I just didnt understand the deeper meaning. Therefore, I left it unchanged because I thought I might have misunderstood it.
-
- It is much easier to throw away contributions of others than to first try understand what they wrote. That's why WikiPedia is not ready to rival other valuable sources of information.
-
-
- I don't know why the SAP link was included, other than that it repeats the claim on the Sun page. It isn't exactly a prominent place for advertising, so that isn't a likely motive.
- Regarding with code with few comments, the goal is to write accurate encyclopedic material. Providing an easy introduction to the language is not. Yes, this page is a mess and needs improvement, but it was worse in the past.
- On the introduction you wrote, see "Original Thought" above. There are rules; follow them and people won't revert your changes.
- Anyway, don't think people are going to revert anything you write here. If you write anything else, I'll defer unless it's very clearly out of bounds. It would be helpful if you wrote a qualifying opening paragraph, or several, summarizing the features of the syntax. Pay attention to the guidelines and no one will probably bother you. Quamaretto 22:23, 28 April 2006 (UTC)
-
[edit] Missing Syntax Structures
This article could stand to mention function literals, regex literals, and possibly object prototyping. 08:10, 16 August 2006 (UTC)
The article is also lacking a discussion of the with() construct. (Not sure if it qualifies as a operator or a syntax, I think technically it is an operator).
[edit] Good Job
This was a great article for someone in need of a quick reference on the specific differences between JavaScript syntax and the syntax of languages like Java and C++ for someone with experience in those languages and working on a small project in JavaScript.
[edit] Miscellaneous and reserved words
I think the Miscellaneous section could stand to be rewritten, and possibly re-titled to Parsing or something. We don't really need a level three head for the simple sentence "JavaScript is case sensitive." Also, JavaScript's reserved words should be added to the article. 209.92.136.131 21:37, 12 December 2006 (UTC)
[edit] Various
Variables : It says : "Variables in standard JavaScript have no type attached, and any value can be stored in any variable.". But when a value is assigned to a variable, its type is recorded - i.e. attached. Something like "A variable in standard JavaScript has no fixed type, and any type of value can be stored in any variable." perhaps? The value 0.1 cannot be stored exactly as a Number, so "any value" might mislead.
Suggest rephrasing (too convoluted?): Variables are variant types [link?no article yet] that can take any value of a small number of types [footnote#1], and which are converted or changed implicitly as needed. In effect, any value can be stored in any variable.
footnote#1: Number, String, Object, Boolean. Functions are Objects, and so can also be stored in variables]
Variables (2): It says: "...[in a function,] variables used without being declared with 'var', are global (can be used by the entire program)."
This needs clarification: Variables declared in a function do have global scope, but are not defined until the function has been evaluated, and a function cannot be evaluated -- at global scope -- until it has been declared. In effect, one must declare before use.
Re the example code: Any use of "twenty" causes ReferenceError until f has been declared, and called at least once.
Note that functions declared inside function scope can be called inside that scope before the source text appears. Again, variables declared without var in inner functions are not usable until the function is called.
Actually, it is a little more complicated that the above paragraph would represent. A variable simply used inside a function without specifying a scope MIGHT be global, but the javascript parser is supposed to start at the bottom of the execution context chain (i.e. the function in which the statement resides), and then iteratively search for a scope higher in the chain. So if you have nested functions, it is possible to use a variable without instantiating it with var but not be available globally, if there is an outer function in which that variable is defined. This is one of the concepts that make closures in JavaScript possible.24.49.69.72 17:50, 7 April 2007 (UTC)
Numbers : It says "... they do not always exactly represent decimal numbers, particularly fractions.". They can represent all integers up to 253 exactly. So "... they do not usually represent decimal fractions exactly."?
Strings : The character set is not presently mentioned - put "sequence of UniCode characters"? A third example might illustrate ' within "...", \t \n, \u03A3 for example. In MSIE6, and as I recall in ECMA-262, strings CANNOT be indexed as arrays.
Arithmetic : Plus is also a unary operator. It is useful for converting String (or Boolean) to Number : Count = +MyForm.Ctrl.value .
Comma : I see no mention of it. No example of a var list, nothing to support for (J=0, K=1 ; K<4 ; K++) {} which I hope is legal.
82.163.24.100 16:56, 31 January 2007 (UTC)