Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need to use unless and "?" together instead of if alone

Tags:

coffeescript

what is the need for using unless and "?" together when you can use if like in this case

unless person.present?

is equivalent to

if person.present
like image 558
coool Avatar asked Apr 18 '13 16:04

coool


1 Answers

They're not equivalent.

doSomeThing() unless person.present? will execute only if person.present is null

doSomeThing() unless person.present will execute if person.present is a false value

doSomeThing() if person.present will execute if person.present is a true value

check the compiled javascript.

like image 180
taiansu Avatar answered Sep 28 '22 13:09

taiansu