- Get the coffee machine
- Fill with water
- Add some coffee
- Turn on the heat
document.write('First this line will be printed out.<br>');
document.write('Then this will be printed.<br>');
// Statements can be written like this
a = 3;
b = 4;
c = a + b;
// Or like this
a = 10; b = 14; c = a - b;
// Semicolons are optional
a = 25
b = 5
c = a / b
If there's no semicolon or newline between two statements the first one will collide with the second, leading to a syntax error and everything crashes.
var x = 5;
// Double slash makes a line a comment
var y = x * 2;
Block comments over multiple lines are written with
slash + asterix
People used to html and css have probably found out it's sometimes a good idea to make comments in your code. Comments are just text that the web browser totally ignores and won't show anywhere on a site, except in the source code. So what's that good for then one could ask himself. They are actually very useful and developers put them everywhere in their code as notes that explains what code does. For example what a function does.
It's also very important for teamwork, so when someone else looks at your code they can easily understand what it does. Without any comments code can be really hard to understand, unless you have very clear variable names and function names. Sometimes it just looks like the matrix with variables, functions and letters all over the place.
There's a joke saying the hardest thing in programming is not really coding, but writing comments. Here's a thread with some tips on both good and bad ways of commenting code: https://stackoverflow.com/q/184618.
Try it yourself
- Write a couple comments between the statements.