Tay Ray Chuan home archive

"&&" as control flow operators

Tue, 10 Aug 2010 23:49:40 +0800 | Filed under random

Recently, despite having zero knowledge of Ruby, I read a Ruby article on and vs &&, via Ruby Inside. It's pretty interesting to note such a distinction in Ruby.

Let's have a look at python and JavaScript.

For python: the C-like && is not available, only and. Using the Python interpreter:

>>> print 1 and "foo"
foo

For JavaScript: the Perl-like and is not available, only &&. Using Chrome's console:

> console.log(1 && "foo")
foo
undefined

So it seems flow control is the name of the game in them both.

blog comments powered by Disqus