When learning any language (be it a programming language or a literary one), we must start with the **grammar, **i.e. the rules that govern with. And for that, we must know what the building blocks of that language are.
Drawing an analogy from a literary language (English) and a programming language (Javascript), we can say the following -
English | Javascript |
---|---|
Story | Software/App |
Chapter | Program/Script |
Paragraph | Function |
Sentence | Statement |
Word | Token |
Alphabet | Character |
Going up the chain, let's see what these are -
These are letters (A-Z,a-z), numbers (0-9), and special characters like !@#$%^&*(), and others. Every language will have a valid set of characters which can be used to write code. Some languages support using letters of foreign languages too. For Javascript, the Unicode charater set is supported, with with various rules and reservations about which characters can or can not be used in different situations.
A token is a single meaningful unit of code. There are tokens like var
which is a keyword for declaring variables, tokens like a simple number 10
which represents the integer 10. Symbols like + - * / = are also tokens
A statement is a single unit of code that makes sense on its own. Similar to what a sentence is in literary languages, when you put tokens together into a line of code, which can be interpreted by the interpreter and some logical step gets taken, that piece of code is called a statement. Some examples are -
var a = 10
which sets that value of **a ** to 10.
console.log('hello')
which prints the word hello to the screen.
A collection of statements, that will execute in a given order (governed by some logic). A process of starting the execution of the statements within a function is called invoking, though, more colloquially, calling a function is correct.