Note that there are some explanatory texts on larger screens.

plurals
  1. POExpressions and Statements in JavaScript
    primarykey
    data
    text
    <p>I just started to learn JavaScript with the book "Eloquent JavaScript", which is accessible free of charge at eloquentjavascript.net. So far I really like the book, there's just one section I don't understand. It's the one about expressions and statements:</p> <p><a href="http://eloquentjavascript.net/chapter2.html#p65af5913" rel="nofollow">http://eloquentjavascript.net/chapter2.html#p65af5913</a></p> <p>I know this topic has been mentioned on StackOverflow before, however, these were more specific questions and I - quite frankly - don't get the whole thing.</p> <p>In the beginning of the paragraph, the author explains what expressions are: If I understand it correctly, atomic values such as 42 or "23" are being considered expressions. If one applied those values to an operator (as in 42 - 19), this would be considered an expression, too. (I guess because it obviously turns out to be 23, which is an atomic value once again.) I interpret this the following way: <strong>Every value - no matter whether it's directly typed in or is yet to be calculated - is being called an expression. Is that correct?</strong></p> <p>Then the author says the following: <em>"There exists a unit that is bigger than an expression. It is called a statement. [...] Most statements end with a semicolon (;). The simplest kind of statement is an expression with a semicolon after it."</em> As an example he mentions <pre>!false;</pre> as an example statement. My questions is <strong>"What makes this a statement? Just the semicolon at the end?"</strong> When I use the JavaScript console, it makes absolutely no difference whether I type that in with or without the semicolon. It always returns true. However, the author says that <em>"[A] statement only amounts to something if it somehow changes the world."</em> <strong>So the given example is not even a statement since it <em>"just produce[s] the value [...] true, and then immediately throw[s it] into the bit bucket"</em>?</strong> I am really confused now... If I did not entirely mess it up in my head, a statement has to have some <em>"side-effect"</em> (like a declaration of a variable), right?</p> <p>However, I would be very happy if someone could explain what a statement is. It would also be very helpful if someone could give an example in which the distinction of those terms is actually useful, because right now I cannot even imagine why the author even bothers to introduce these vocabularies. Thank you very much in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload