LoginSignup
6
6

More than 5 years have passed since last update.

CoffeeScriptで三項演算子

Last updated at Posted at 2012-08-10
hoge ? piyo : fuga

ってかくと、JavaScriptでは

if (typeof hoge !== "undefined" && hoge !== null) {
  hoge;

} else {
  ({
    piyo: fuga
  });
};

期待した形じゃない。幸福じゃない。
幸福は欲しいから。

if hoge then piyo else fuga

こう書いた。

if (hoge) {
  piyo;

} else {
  fuga;

}

期待した形ぽい。幸福だ。

6
6
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6