{"action":"created","issue":{"url":"https://api.github.com/repos/thechangelog/ping/issues/229","labels_url":"https://api.github.com/repos/thechangelog/ping/issues/229/labels{/name}","comments_url":"https://api.github.com/repos/thechangelog/ping/issues/229/comments","events_url":"https://api.github.com/repos/thechangelog/ping/issues/229/events","html_url":"https://github.com/thechangelog/ping/issues/229","id":88333637,"number":229,"title":"[JavaScript] if-exp - conditional expressions for JavaScript","user":{"login":"FGRibreau","id":138050,"avatar_url":"https://avatars.githubusercontent.com/u/138050?v=3","gravatar_id":"","url":"https://api.github.com/users/FGRibreau","html_url":"https://github.com/FGRibreau","followers_url":"https://api.github.com/users/FGRibreau/followers","following_url":"https://api.github.com/users/FGRibreau/following{/other_user}","gists_url":"https://api.github.com/users/FGRibreau/gists{/gist_id}","starred_url":"https://api.github.com/users/FGRibreau/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/FGRibreau/subscriptions","organizations_url":"https://api.github.com/users/FGRibreau/orgs","repos_url":"https://api.github.com/users/FGRibreau/repos","events_url":"https://api.github.com/users/FGRibreau/events{/privacy}","received_events_url":"https://api.github.com/users/FGRibreau/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-15T06:27:46Z","updated_at":"2015-07-10T16:20:03Z","closed_at":null,"body":"Some languages implement conditionals (and other well known statements) as expressions, so we can write:\r\n\r\n```\r\nval res = if(condition){\r\n    'result 1'\r\n} else if(secondCondition) {\r\n    'result 2'\r\n} else if(thirdCondition) {\r\n    'result 3'\r\n} else {\r\n    'result 4'\r\n}\r\n```\r\n\r\nWhile in JavaScript, conditional expressions can be achieve using ternary operators. Multiple conditions are sometimes hard to read using ternary:\r\n\r\n```javascript\r\nvar res = condition ?  'result 1' : \r\n    (secondCondition ? 'result 2' : \r\n        (thirdCondition ? 'result 3' : 'result 4'));\r\n```\r\n\r\nHere is how to write the same thing with iff:\r\n\r\n```javascript\r\nvar res = iff(condition)\r\n            .then('result 1')\r\n        .elseIff(secondCondition)\r\n            .then('result 2')\r\n        .elseIff(thirdCondition)\r\n            .then('result 3')\r\n        .otherwise('result 4');\r\n```"},"comment":{"url":"https://api.github.com/repos/thechangelog/ping/issues/comments/120449903","html_url":"https://github.com/thechangelog/ping/issues/229#issuecomment-120449903","issue_url":"https://api.github.com/repos/thechangelog/ping/issues/229","id":120449903,"user":{"login":"jerodsanto","id":8212,"avatar_url":"https://avatars.githubusercontent.com/u/8212?v=3","gravatar_id":"","url":"https://api.github.com/users/jerodsanto","html_url":"https://github.com/jerodsanto","followers_url":"https://api.github.com/users/jerodsanto/followers","following_url":"https://api.github.com/users/jerodsanto/following{/other_user}","gists_url":"https://api.github.com/users/jerodsanto/gists{/gist_id}","starred_url":"https://api.github.com/users/jerodsanto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jerodsanto/subscriptions","organizations_url":"https://api.github.com/users/jerodsanto/orgs","repos_url":"https://api.github.com/users/jerodsanto/repos","events_url":"https://api.github.com/users/jerodsanto/events{/privacy}","received_events_url":"https://api.github.com/users/jerodsanto/received_events","type":"User","site_admin":false},"created_at":"2015-07-10T16:20:03Z","updated_at":"2015-07-10T16:20:03Z","body":"@FGRibreau is `iff` a library that you wrote? Have a link for more info? Thanks!"}}