0

Here is the code

let name1 = "nobody"
let name2 = ctx.request.query.name || name1;

This code is equivalent to

let name2 = ctx.request.query.name?ctx.request.query.name:name1

I thought here || is or, and is this a function in ctx.request.query?

Bin
  • 484
  • 1
  • 6
  • 18
  • Possible duplicate of [What does the construct x = x || y mean?](https://stackoverflow.com/questions/2802055/what-does-the-construct-x-x-y-mean) – Sven Aug 06 '18 at 04:30
  • 1
    See the [2nd answer](https://stackoverflow.com/a/34707750/1765851) in that question, which explains the behaviour very well. – Sven Aug 06 '18 at 04:31

0 Answers0