I like it when "if" is an expression

by: Ethan McCue

One of the small conveniences ive grown to really like in a programming language is "if" being an expression.

I found myself hacking it into some JS I was writing today.

const thing = (() => {
    if (condition) {
        return "hello";
    } else {
        return "world";

Now, feel free to weigh in on that being bad practice.

as a non JS programmer I have no idea what "thing = (() => {" is supposed to do

That creates an anonymous function then calls it immediately.

<- Index