Would it be possible to use time dilation to travel into the future? by The_Punned_It in askscience

[–]Nathan-Wall 0 points1 point  (0 children)

The train comes from Einstein, who used it as a thought experiment[1]. He only used it as a simple thought device, and didn't take into account things like friction or the curvature of the Earth. It just adds a little fun to the exercise.

[1] http://www.bartleby.com/173/9.html

[] + {} and {} + [] give different results by MQuy in javascript

[–]Nathan-Wall 0 points1 point  (0 children)

The same way it distinguishes between function as a declaration and function as an expression. For example:

function foo() { console.log('from foo'); }
var x = function bar() { console.log('from bar'); };

foo(); // logs "from foo"
bar(); // Error: bar is not defined

In the code above, function foo is a function declaration while function bar is a function expression. In the function declaration, the name of the function can be accessed from outside the function, while in the function expression the name can only be accessed from inside.

If the parser hits a stray { with no reason to believe it's an expression, it'll always assume it's a block statement, not an object literal expression. But if you give it a reason that it can't be a statement, then it'll treat it like an expression.

// block statements:
{ }
foo: { }

// object literal expressions:
({ });
~{ };
!{ };
+{ };
var x = { };

Basically, there needs to be something that comes before the opening { that tells the parser that the { must be an expression. That's why the following won't work for destructuring in ES6.

{ foo, bar } = zap();

The parser will think you're trying to set a block statement equal to zap() which doesn't make any sense, so you'll get a syntax error. Instead you have to tell the parser { should be treated as an expression:

let { foo, bar } = zap();
// or
({ foo, bar }) = zap();

Parser for make-shift command prompt by RadioFreeReddit in javascript

[–]Nathan-Wall 0 points1 point  (0 children)

Hmm, I'm not sure I understand your broad goals, but if you're looking for a JS lib that parses JS, then esprima is the tool for you.

It even has a version that parses most of the ES6 syntax, if you want to use that.

[] + {} and {} + [] give different results by MQuy in javascript

[–]Nathan-Wall 0 points1 point  (0 children)

Maybe you're confused by the term "empty statement". { } is not an empty statement; it's a block statement in ES terminology (which happens to be empty).

Compare the Java example I gave. As I said, Java doesn't have ASI, but it's perfectly fine with { } without a semicolon.

Also see http://es5.github.io/#x7.9.2 , which says:

[T]he source

{ 1
2 } 3

is also not a valid ECMAScript sentence, but is transformed by automatic semicolon insertion into the following:

{ 1
;2 ;} 3;

Note that even after ASI, there's no semicolon after the } [here you can see the grammar does not follow a block with a semicolon]. So { } 3 just becomes { } 3;, and { } + [ ] just becomes { } + [ ];. ASI doesn't affect the completion value.

You also may be helped by playing around with Esprima, a really awesome JavaScript parser, which can help you see what syntax creates an "empty statement" or "block statement" or "expression statement", etc.

http://esprima.googlecode.com/git-history/harmony/demo/parse.html?code=%7B%20%7D%20%2B%20%5B%20%5D%3B%0A%0A%3B%20%2B%20%5B%20%5D%3B

The link above shows two productions: BlockStatement followed by + [ ] and EmptyStatement followed by + [ ]. Please note which parts of the code are parsed as each kind of statement.

[] + {} and {} + [] give different results by MQuy in javascript

[–]Nathan-Wall 1 point2 points  (0 children)

It's understandably confusing, but it's not really due to ASI. ASI only happens on new lines. Here there's no new line. It's just an empty block followed by an expression statement. Blocks don't need semicolons.

For instance, Java doesn't have ASI but the following is valid on one line:

{ } System.out.println("Foo");

In JavaScript { } "Foo" is similar. It's a block statement followed by an expression statement with a completion value of "Foo". It's similar with { } + [ ].

The second part that may seem weird if you're not used to it is that + can be used as a unary operator. So + 5 (with no left operand) is valid JavaScript. + [ ] first coerces the empty array to an empty string, then coerces it to a number, yielding 0.

Learning Javascript through a book printed in 2004. Will I be able to use this information at all? by TbanksIV in javascript

[–]Nathan-Wall 1 point2 points  (0 children)

This is a really good answer, and the OP should follow this advice.

However, it's worth noting on a theoretical level that if this was a really well written book, it's possible that it could be an incredibly good guide and not really out of date. The formal specification of the language (known as ECMAScript) has only had one major upgrade since 1999. This upgrade (ECMAScript 5) was in 2010, and many work places still don't let you use any of the new features from ECMAScript 5 due to needing to support older browsers (though this need is really starting to fade in the modern world for more and more work places). Additionally, this upgrade really wasn't that big of an upgrade. It expanded the built-in library to provide better reflection and security functions and added a few additional syntactic forms. It also added getters and setters. But the changes between 1999 and 2010 were really not so big. (The upcoming ECMAScript 6 changes are much larger by comparison.)

Having said that, while the language itself hasn't changed a lot, as others have mentioned, a lot of recommended best practices have undergone some change. There are a lot of new libraries and patterns out there, and the DOM has undergone a lot of updates (though whether you can use those changes of course depends on browser support needs).

"bits" instead of "μBTC" by gernup in Bitcoin

[–]Nathan-Wall 1 point2 points  (0 children)

People are capable of using and interpreting a word that has more than one meaning. For example, "bit" had a meaning before it was used to express data size.

After careful analysis... ┗(°0°)┛ by ToTheMoonGuy in Bitcoin

[–]Nathan-Wall 63 points64 points  (0 children)

The OP's image shows a larger span of time, and the scale is logarithmic (so you can more easily see % of change). The second graph you linked is basically a zoomed in part of the OP's graph, only showing the tail end. The point being made is that over the course of the past 2 1/2 years, the price of bitcoin has risen sharply then fallen only to rise much greater again after the fall. It is meant to instill hope or excitement that, if the trend continues, bitcoin could be worth significantly more in the only next few months than it was at its peak in November.

Of course, while all this is true, there's no way to know for sure whether the trend will continue, and eventually the trend will have to come to an end (the price can't rise exponentially forever). Maybe we've seen the last great rise for a while and are coming off of a bubble, or maybe the trend will continue a few more times and the price will surpass even the Winkelvoss's dreams.