How to programmatucally check in JavaScript whether the current Discourse user is authenticated?

You can do it by comparing the Discourse.User.current() expression with null.

An example:

Another example (2018-03-28)

See also:

How to show the «Log In» popup programmatically?