r/badcode • sadistic • Apr 22 '21

js ternary operators at their maximum potential

Post image
960 Upvotes

73 comments sorted by

View all comments

1

u/fugogugo Apr 23 '21

what does that || 4 does?

3

u/skrtpowbetch Apr 23 '21 edited Apr 23 '21

i might be wrong but i think what that says is the value assigned to type would be cmd.type if it’s truth-y, else 4. not completely sure though

edit: “type” will equal cmd.type if cmd.type is defined, else 4

4

u/fforde_thinking Apr 23 '21

You were right the first time. If cmd.type == false then it will set "type" to 4