########################################################################
myVariable = 1
From this point on the variable myVariable contains 1. You can change this at any point just by assigning a new value. If you ask the value of a variable before it has one (defined) it returns a special value 'undefined'.
myUnexistingVariable # Returns 'undefined'
#Variables can store different types of data, see below.
########################################################################
myBoolA = true myBoolB = false
myNumberA = 1 myNumberB = 55.0 myNumberC = -223894
myNumberA + myNumberB # Output: 66.0 myNumberA / myNumberB # Divide myNumberA * myNumberB # Product myNumberA ** myNumberB # Power
myStringA = "Hello there"
myStringB = "#{myStringA}, I am the dude"
myStringC = "rgba(255,0,0,0.1)" myStringD = "1px solid #FFFFFF"
Lists contain an ordered set of values. The values can be any type. They can even be nested (list of lists).
myListA = [1, 2, 3, 4, 5] # Just numbers myListB = [1, "test", 22, [1, 2, 3]] # Mixed
myListA[0] # Output: 1 myListA[4] # Output: 5
myListB.length # Output: 4
myListB[0..2] # Output: [1, 2, 3]
Objects are a bit like lists, but instead of by number, you can access them by a string (word). Much like a dictionary from a phone book (look up a person by last name). We call the 'lookup string' a key.
myObjectA = {name: "Framer", age:12}
myObjectB = name: "Framer" age: 12
myObjectB["name"] # Output: "Framer"
myObjectB["skdjslkdj"] # Output: undefined
myObjectB["platform"] = "Mac"
delete myObjectB["platform"] myObjectB["platform"] # Output: undefined
########################################################################
Functions are bits of code that you can execute. It's pretty much the same thing as a function in mathematics. They take input and generate output. The part in between is just a description how to get from one to the other. When you 'run' a function for a specific set of inputs, programmers say you 'call' the function, and the input(s) are 'arguments'. Let's start with a simple example:
myFunction = (input) -> output = input * 2 return output
myFunction(42) # Output: 84
myCalculatedNumber = myFunction(42) myCalculatedNumber # Output: 84
########################################################################