coffee.sample in Code Block Pro – Beautiful Syntax Highlighting 1.27.5, at build/shiki/samples/coffee.sample
| 1 | # Assignment: |
| 2 | number = 42 |
| 3 | opposite = true |
| 4 | |
| 5 | # Conditions: |
| 6 | number = -42 if opposite |
| 7 | |
| 8 | # Functions: |
| 9 | square = (x) -> x * x |
| 10 | |
| 11 | # Arrays: |
| 12 | list = [1, 2, 3, 4, 5] |
| 13 | |
| 14 | # Objects: |
| 15 | math = |
| 16 | root: Math.sqrt |
| 17 | square: square |
| 18 | cube: (x) -> x * square x |
| 19 | |
| 20 | # Splats: |
| 21 | race = (winner, runners...) -> |
| 22 | print winner, runners |
| 23 | |
| 24 | # Existence: |
| 25 | alert "I knew it!" if elvis? |
| 26 | |
| 27 | # Array comprehensions: |
| 28 | cubes = (math.cube num for num in list) |
| 29 | |
| 30 | # From https://coffeescript.org/#overview |