Skip to content

Instantly share code, notes, and snippets.

@mbuttler
Created May 23, 2015 21:30
Show Gist options
  • Save mbuttler/8b766143d579ccc10fd1 to your computer and use it in GitHub Desktop.
Save mbuttler/8b766143d579ccc10fd1 to your computer and use it in GitHub Desktop.
var isEven = function(number) {
// Your code goes here!
if (number % 2 === 0)
return true;
else
return false;
};
@mbuttler
Copy link
Author

Why is this syntactically valid? Shouldn't curly braces be required?

@Tetsuro
Copy link

Tetsuro commented May 23, 2015

You don't need curly braces if anything after the if and else is in a single line :)

You'll need curly braces if you need multiple lines.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else
http://stackoverflow.com/questions/7117873/do-if-statements-in-javascript-require-curly-braces

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment