From the course: Learning CoffeeScript

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Working with conditional statements

Working with conditional statements - CoffeeScript Tutorial

From the course: Learning CoffeeScript

Start my 1-month free trial

Working with conditional statements

Conditionals follow the CoffeeScript tradition, of trying to simplify things. A simple if statement looks simpler in CoffeeScript, but it's quite different than the ones we're used to in JavaScript. Let's go ahead and create a very basic if statement in CoffeeScript. We would say something like, if name equals, equals, and then something like my name, then you can do something else, name, equals, and then we'll put in my full name here. So right now we obviously don't have a variable called name, so we'll go ahead and create it and set it to my first name. So let's go ahead and save that and see what it translates to. Now, there's a few interesting things that CoffeeScript just did. We didn't of course need any parentheses, but notice that the double equal sign automatically converted into a triple equal, and that's actually good JavaScript practice. Double equals sign does something called type coercion, which means it tries to make values of different types, like strings and…

Contents