See short-circuit evaluation for the explanation. It's a common way of implementing these operators; it is not unique to JavaScript.
Answer from unwind on Stack OverflowJavaScript OR (||) variable assignment explanation - Stack Overflow
What is the purpose of the global object in JavaScript?
Why is everything considered a variable in javascript?
JavaScript has first-class-functions (*1), thats why you can assign functions to variables. JavaScript has no classes like Java does. JavaScript uses prototype inheritance (*2) and has only 'objects'. To work with objects you must assign them to variables, just like you do in Java, right?
And don't let ES6 confuse you. Even ES6 does not have real classes. The class syntax in ES6 is just syntactic sugar on top of the <=ES5 prototype system ..
The good thing is you have only three things in JavaScript: Everything is either a function (and some folks may also argue that a function in JS is a special object), an object or a primitive. And there are only a few primitives as well .. makes the language pretty simple. But sometimes simpler is better ;)
*1: https://en.wikipedia.org/wiki/First-class_function
More on reddit.com*2: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain
JS: Assigning values to multiple variables
Videos
See short-circuit evaluation for the explanation. It's a common way of implementing these operators; it is not unique to JavaScript.
This is made to assign a default value, in this case the value of y, if the x variable is falsy.
The boolean operators in JavaScript can return an operand, and not always a boolean result as in other languages.
The Logical OR operator (||) returns the value of its second operand, if the first one is falsy, otherwise the value of the first operand is returned.
For example:
"foo" || "bar"; // returns "foo"
false || "bar"; // returns "bar"
Falsy values are those who coerce to false when used in boolean context, and they are 0, null, undefined, an empty string, NaN and of course false.