Core programming fundamentals · Lesson 2 of 60 · Concept lesson · Optional
Syntax and semantics
Syntax is the set of rules for how code must be written, like the grammar of a sentence.
Semantics is what the code means, which is what it actually does when it runs.
Code can follow the syntax perfectly and still do the wrong thing.
Picture it
Code example
console.log(4 + 6 / 2);
console.log((4 + 6) / 2);Output:
7 5
Both lines are valid syntax. They print 7 and 5, because the brackets change the meaning.
print(4 + 6 / 2)
print((4 + 6) / 2)Output:
7.0 5.0
Both lines are valid syntax. They print 7.0 and 5.0, because the brackets change the meaning.
Check yourself
Pick an answer for each question. You can retry as many times as you like.
Loading the questions…