alert "Hello CoffeeScript!"
comment: 複数行コメント commentが残るcomment記法
var score = 82; if (score > 80) { alert("OK"); }
score = 82 if score > 80 alert "OK"
alert "score is: " + score
alert "score is: #{score}"
alert "score is: #{score * 10}"
msg = "this is hoge and that is foofoo"
a = [1,2,3,4,5] b = [ 1 2 3 ]
m = {name: "yamada", score: 80}
m = name: "yamada", score: 80
m = name: "yamada" score: 80
n = name: "tanaka" score: first: 10 second: 20 third: 90 time: 8.2
if score > 60 then alert scrore
alert scrore if score > 50
if score > 60 alert "OK" else alert "NG"
if score > 60 then alert "OK" else alert "NG"
可読性として良くないのでcoffeeでは記述不可、代わりに下記
msg = if score > 60 then "ok" else "NG"
alert = "OK" if 10 < x < 20
alert "OK" if answer is yes and signal isnt off
alert "OK" if 5 in [1,2,3,4,5]
alert "OK" if "score" of o
switch (signal) { case "red": alert("STOP"); break;
case "blue": case "green": alert("GO"); break;
case "yellow": alert("CAUTION"); break;
default: alert("wrong signal!"); }
switch signal when "red" alert "STOP" when "blue", "green" then alert "GO" when "yellow" then alert "CAUTION" else alert "wrong signal!"
sum = 0 for i in [0..9] sum += 1 alert sum
for color in ["red", "blue", "yellow"] alert color
obj = hoge: 1 foo: 2 fuga: 3
for key, val of obj alert "#{key} は #{val} です"
hello = (name) -> alert "hello #{name}"
hello = (name = "tanaka") -> alert "hello #{name}"
(function() { alert ""hello })();