Talk:JavaScript syntax

message: 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)
thread_title:  Inheritance without prototyping, etc. 

message: 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.
Yes, thanks a lot to the author(s). Short and to the point.  —Preceding unsigned comment added by 84.167.27.253 (talk) 19:02, 29 May 2008 (UTC)
thread_title:  Good Job 

message: 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)
thread_title:  Miscellaneous and reserved words 

message: 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)
thread_title:  Various 

message: This is really nice, but I think it would be good to have one paragraph on multidimensional arrays and some examples of declaring and using them since (at least for 2 dimensions) this is a very common usage.  —Preceding unsigned comment added by 167.1.146.100 (talk) 12:59, 8 February 2008 (UTC)
thread_title:  Multidimensional Arrays 

message: All major standards compliance browsers support __proto__ object in Elements, as well as __defineGetter__ and __defineSetter__. Perhaps this should be incorporated into the document?  —Preceding unsigned comment added by Yhulkdsfdd (talk • contribs) 17:44, 11 September 2008 (UTC)
replies: text: Since it's hard to determine what's in JavaScript or not because of the lack of a spec delineating differences from ECMAScript, I'm not sure we should mention __proto__, __defineGetter__, and __defineSetter__. --Maian (talk) 21:34, 11 September 2008 (UTC)
thread_title:  "Modern Day" Prototyping 

message: Should it not be explained that the following:
if(x==1){
   something()
}
else if(x==2){
   somethingelse();
}
the else if works like a shorthand if (without {})
if(x==1)
  do something here
so really it is
if(x==1){
   something()
}
else{
   if(x==2){
      somethingelse();
   }
}
Sorry if that didn't make sense, I find it hard to explain.
: To me, this is an implementation detail. Can you give an example of different behavior (from programmer point of view) between else { if(...){ } } and elsif(...){ } constructions? — Hypher (talk) 08:38, 20 March 2011 (UTC)
thread_title:  [edit] If ... else 

message: Sections of the CLJ FAQ are being reordered and convered from numeric anchors to textual ones.  When that is finished, Wiki should be searched for such references to be corrected.  I have updated the two in this Article. 82.163.24.100 (talk) 18:34, 12 October 2008 (UTC)
thread_title:  FAQ references changing 

message: Much of what is written about this on the web is wrong or misleading or too tangled up in browser semantics to be intelligable.  So I have added succinct, non-trivial examples that highlight the issues.  I learnt a bit in the process.  All examples have been tested.
I hope others find this useful, particularly those comming from other OO languages that are quite different.
The article should probably be renamed to something like JavaScript Language rather than Syntax.  Syntax without semantics is useless.  But I think the contents is quite good at the moment -- a short sharp overview.
The JavaScript Prototypeing logic is quite bizzar IMHO.  Classical Lisp IS-A links would be fine.  But in JavaScript it is confused by C++ thinking.  MyFunction.prototype is plain wrong -- it should simply be this.prototype = parent.  No need for magic.  
Tuntable (talk) 07:47, 3 February 2009 (UTC)
thread_title:  Reworked Methods and Inheritance 

message: The article states that For...In is not useable with arrays, but the W3Schools website gives arrays as an example of the use of For...In:
http://www.w3schools.com/js/js_loop_for_in.asp
and the Microsoft Developer Network specifically states that For...In can be used for "stepping through ... all the elements of an array", without giving any warning about unexpected results. (This is referring to JScript, rather than JavaScript, admittedly, and I don't understand the relationship between the two.)
http://msdn.microsoft.com/en-us/library/kw1tezhk(VS.85).aspx
FrankSier (talk) 15:44, 6 February 2009 (UTC)
replies: text: I have done some research on this subject - not original research :) - and modified the article mainly by putting in some inline references. FrankSier (talk) 21:37, 7 February 2009 (UTC)
thread_title:  For...In and Arrays: useable together or not? 

message: Method toFixed should not be recommended for the web because it is unreliable in MS IE 7 and I think all previous versions of IE that had it - 0.07.toFixed(1) gives 0.0.
The algorithm for StrU currently in http://www.merlyn.demon.co.uk/js-rndg1.htm#GC has no known errors. 82.163.24.100 (talk) 18:44, 3 April 2009 (UTC)
replies: text: No, JScript, at this time, is ECMAScript 3, so is JavaScript 1.5. Confirmed by Wikipedia via a quote from Douglas Crockford: http://en.wikipedia.org/wiki/JScript#Comparison_to_JavaScript . --Hibou57 (talk) 20:09, 18 July 2013 (UTC)
thread_title:  Method toFixed 

message: Is there a reason that println is used in the examples instead of alert? I like JavaScript on client and server, and code in it everyday (helps pay the bills), but I _wouldn't_ be coding in JavaScript if it wasn't for the ubiquitous web browser. Given JavaScript was invented as a browser scripting Language, would anyone be opposed to me swapping out println and replacing it with alert? I would also change the note at the top of the page noting how alert assumes any user who cuts and pastes the examples will be working in a browser. Jeremywosborne (talk) 21:02, 15 April 2009 (UTC)
replies: text: I was the one that replaced all the document.write/alert references with println. To me, JavaScript is just a language that just happens to be used most often on the web. I was trying to keep the article as specific to the language as possible, without complicating it with the DOM, which is NOT part of JavaScript. But I'm happy enough as long as there is a note explaining that document.write/alert is not part of JavaScript and is only used because the browser is the most common host of JavaScript. --Maian (talk) 07:50, 22 April 2009 (UTC)

text: Thanks for the response Maian. It's very difficult to create demonstrable JavaScript examples with the lack of a standard output function. After so many hours coding in this sometimes great, sometimes atrocious language, I figured I'd err on the side of making things browser compliant. Jeremywosborne (talk) 20:09, 22 April 2009 (UTC)
thread_title:  alert vs. println 

message: The code could be changed to also illustrate the ternary operator ? : :
return diff > 0 ? gcd(segmentB, diff) : gcd(segmentA, -diff)
Since the code might be copied, it would be well to change it, after testing, to the more efficient method, in which the second argument to the internal gcd is either A mod B or B mod A, which is approximately equally easy to read; or to the wondrous non-recursive form :
function GCD(U, V) { // or HCF
  while (true) {
    if (!(U %= V)) return V
    if (!(V %= U)) return U } }
And, for the same reason, the alternative acronym HCF should be included. 82.163.24.100 (talk) 20:01, 24 July 2009 (UTC)
thread_title:  Functions 

message: I have completed the list of Native Objects by reference to the Standard.
The page should not be allowed to get too long, and giving much detail on Native Objects would use a lot of space.  How about a new page for JavaScript Objects, with the entries on the Syntax page being condensed to about the size of the first paragraph about Arrays? 82.163.24.100 (talk) 11:51, 26 July 2009 (UTC)
thread_title:  Native Objects 

message: The text claims that the constructor function called when instantiating an object (i.e., the function referenced from a "new" expression) is "not remembered."  That is false in all major browsers: the "constructor" property of every object contains a reference to the constructor function. (Pointym5 (talk) 16:34, 29 December 2009 (UTC)
thread_title:  Constructors and Object Creation 

message: WHERE ARE THE RULES FOR ALL THE LEGAL BUT WIERD CHARACTERS IN IDENTIFIERS? (e.g. "$", "_", etc) —Preceding unsigned comment added by 24.129.93.200 (talk) 16:29, 16 September 2010 (UTC)
replies: text: Added to JavaScript_syntax#Variables: "An identifier must start with a letter, underscore (_), or dollar sign ($); subsequent characters can also be digits (0-9). Because JavaScript is case sensitive, letters include the characters "A" through "Z" (uppercase) and the characters "a" through "z" (lowercase). Starting with JavaScript 1.5, you can use ISO 8859-1 or Unicode letters (or \uXXXX Unicode escape sequences) in identifiers."—Machine Elf 1735 (talk) 00:18, 17 September 2010 (UTC)
thread_title:  Characters allowed in identifiers 

message: "Truthy" and "Falsey"... feel free to source them and say something about them.—Machine Elf 1735 (talk) 01:09, 5 March 2011 (UTC)
thread_title:  Truthy and Falsey 

message: var obj1 = {a : 1};
var obj2 = {b : 2};
function foo(p) {
  p = obj2; // ignores actual parameter
  p.b = arguments[1];
}
foo(obj1, 3); // Does not affect obj1 at all.  3 is additional parameter
alert(obj1.a + " " + obj2.b); // writes 1 3
This is misleading because obj1 can be modified by the function. It is quite odd (in an explanation) to pass a parameter to a function and then ignore it.
Consider:
var obj1 = {a : 1};
var obj2 = {b : 2};
function foo(p) {
 p.a = 7;  // modifies global variable obj1
  p = obj2; // no effect on obj1, ignores actual parameter
  p.b = arguments[1];// modifies global variable obj2
}
foo(obj1, 3); // Does affect obj1.  3 is additional parameter
alert(obj1.a + " " + obj2.b); // writes 7 3
Because the object parameter is passed by reference it can be modified.
This is OR for me. I am just learning. But I was surprised that obj1 can be modified in the function, by p.a=7, yet p=obj2 does not affect obj1. This should be explained. QuentinUK (talk) 02:27, 28 June 2011 (UTC)
thread_title:  Function example code misleading 

message: Is this a long winded way of saying "null, Infinity, NaN, true, false"? What other boundary values are there?   QuentinUK (talk) 11:49, 21 July 2011 (UTC)
replies: text: Number.MIN_VALUE and Number.MAX_VALUE come to mind: the global properties Infinity and NaN (same as Number.POSITIVE_INFINITY and Number.NaN, there's also Number.NEGATIVE_INFINITY) are a bit philosophical... they're special values with particular results specified for comparisons/casts/calculations. (I think true, false, and null are keywords as opposed global properties). I would definitely remove the generalization.—Machine Elf 1735 01:22, 24 July 2011 (UTC)
replies: text: These are not mentioned so the initial statement is misleading. Also there is a range of numbers between Number.MAX_VALUE and Number.POSITIVE_INFINITY, "so boundaries" is also misleading. QuentinUK (talk) 03:27, 25 July 2011 (UTC)
thread_title:  Some of the primitive data types also provide a set of named values that represent the extents of the type boundaries. These named values are described within the appropriate sections below. 

message: I've seen strings defined as 
    var greetings = /Hello World!/
what's going on here, ie how come this is not mentioned in the article.
QuentinUK (talk) 12:08, 21 July 2011 (UTC)
replies: text: It's a regular expression object literal.—Machine Elf 1735 01:22, 24 July 2011 (UTC)
thread_title:  Strings 

message: One problem with this article is that you can not read it from start to end. ie In the Boolean section it discusses the == operator and the || and && operators before they and their odd behaviour are mentioned.
    // That the following are different surprised me:-
    alert(2 && true); // true
    alert(true && 2); // 2
    // also
    alert(2==2==1); // true
    alert(1==2==2); // false
    // But if the rules were explained first they wouldn't have.
QuentinUK (talk) 17:39, 21 July 2011 (UTC)
replies: text: I got tired of reverting an obnoxious IP who didn't understand coercion issues. For whatever reason, they were fixated on the section about the Boolean constructor but should have focused on the sections about the operators... comparison, assignment, conditional, logical... Machine Elf 1735 01:22, 24 July 2011 (UTC)
thread_title:  Split Boolean 

message: The following 
alert(   !0 === Boolean(  !0 ) ===   !!1 === Boolean(    1 ) === true  );
alert(  !!0 === Boolean(   0 ) ===    !1 === Boolean(   !1 ) === false );
alert(  !"" === Boolean( !"" ) === !!"s" === Boolean(  "s" ) === true  );
alert( !!"" === Boolean(  "" ) ===  !"s" === Boolean( !"s" ) === false );
Gives the impression that equality can be chained together. A===B===C being true when they are all equal, this is not the case. QuentinUK (talk) 10:57, 11 August 2011 (UTC)
thread_title:  Strict equals transitivity 

message: In the "Variable" section, shouldn't there be a word about usage of the keyword var? What happens when you use it? What happens when you don't?
Also, the section on semicolons reads like a personal blog and contains a reference to an outside blog. --Tim Sabin (talk) 17:58, 13 April 2012 (UTC)
thread_title:  Variable declaration 

message: The examples for -= and /= (shorthand for non-commutative operations) don't currently allow the reader to infer the order of the operations.  If we start with x=3, it isn't clear why the result of  x /= 3  is  1.  Was it because x was divided by 3, or because 3 was divided by x? For this reason I am changing the numerical values in the example sequence. Evaluist (talk) 22:42, 15 November 2012 (UTC)
thread_title:  Assignment Examples -- Primitive Types 

message: Unless some one sees an issue with it, I will add this to the way to check for the `undefined` special value:
    function isUndefined (o) {
       return ((typeof o) === "undefined");
    }
Seems the way using `typeof` is missing in the document.
--Hibou57 (talk) 19:25, 18 July 2013 (UTC)
thread_title:  Testing for `undefined` 

message: MDN and MSDN both talk of a spread operator, written "..." and it's not covered here or on other places I've been able to find on Wikipedia about JS or ES6. Then again I've been told that even though major JS sources call ... an operator it may not technically be an operator. — Hippietrail (talk) 06:08, 27 January 2016 (UTC)
replies: text: I took a try at creating a section about the spread/rest operator "...". I placed it in the section on operators, although now that I think about it, it's probably true that it's not an "operator" in the strict sense. It's more like syntactic punctuation, along the same lines as "[]", "{}", commas, and semicolons. In which case, rest parameters should perhaps be moved into the section on functions, and spread syntax should be moved into the section on arrays (and maybe also mentioned in the section on funcions). --2404:130:0:1000:102E:358C:1F00:94A4 (talk) 06:48, 29 September 2016 (UTC)
thread_title:  Doesn't mention ES6's "spread operator": ... 

message: Concerning editing and maintaining JavaScript-related articles...
=== Collaboration...===
If you are interested in collaborating on JavaScript articles or would like to see where you could help, stop by Wikipedia:WikiProject JavaScript and feel free to add your name to the participants list. Both editors and programmers are welcome.
 
=== Where to list JavaScript articles ===
We've found over 300 JavaScript-related articles so far. If you come across any others, please add them to that list. 
=== User scripts ===
The WikiProject is also taking on the organization of the Wikipedia community's user script support pages. If you are interested in helping to organize information on the user scripts (or are curious about what we are up to), let us know!
If you have need for a user script that does not 
yet exist, or you have a cool idea for a user script or gadget, you can post it at Wikipedia:User scripts/Requests. And if you are a JavaScript programmer, that's a great place to find tasks if you are bored.
=== How to report JavaScript articles in need of attention ===
If you come across a JavaScript article desperately in need of editor attention, and it's beyond your ability to handle, you can add it to our list of JavaScript-related articles that need attention.
=== Rating JavaScript articles ===
At the top of the talk page of most every JavaScript-related article is a WikiProject JavaScript template where you can record the quality class and importance of the article.  Doing so will help the community track the stage of completion and watch the highest priority articles more closely.
Thank you. The Transhumanist 01:10, 12 April 2017 (UTC)
thread_title:  Maintenance and rating of JavaScript articles 

message: At the top of the talk page of most every JavaScript-related article is a WikiProject JavaScript template where you can record the quality class and importance of the article.  Doing so will help the community track the stage of completion and watch the highest priority articles more closely.
Thank you. The Transhumanist 01:10, 12 April 2017 (UTC)
thread_title:  Rating JavaScript articles 

message: I thought the commenting on the examples was very good up until the last example in the Function session & several in the Objects section.  Without having the ability to set breakpoints to follow the logic, I had trouble understanding what the author wanted to demonstrate.
  I don't know if my sentiment is widespread because I am self-taught and may have missed some implied points along the way.  Otherwise, I thought it was well-done. The Source Whisperer (talk) 03:58, 6 May 2019 (UTC)
thread_title:  Comments Please 

message: An editor has asked for a discussion to address the redirect With statement. Please participate in the redirect discussion if you wish to do so.  — Arthur Rubin  (talk) 10:56, 19 May 2019 (UTC)
thread_title:  With statement listed at [[Wikipedia:Redirects for discussion|Redirects for discussion]] 

message: Module syntax which is the most basic thing of every JS interpreter is missing. I suggest to make section on how module system works per different implementations like browser/server(e.g. Google Chrome/Node.js). I suggest to avoid making it bloated as to address issue pointed out by . AXONOV (talk) ⚑ 08:35, 13 October 2020 (UTC)
thread_title:  Module syntax