This will be my first time “teaching” anyone Java Script but I will do my best in this lesson and the next couple to explain the very basics of the language and how it works.
The first thing that you need to understand is that every coding language has a syntax. This is the way that the code is written and what specific signs or symbols may need to be typed in to make it work/run. The most basic and arguably most important syntax in Java Script is the semicolon “;”. This handy character allows us to essentially finish our lines of code in Java Script letting the computer know that we are done typing into this specific line of code. Forgetting to type this symbol at the end of lines of code is the most basic error that is made by beginners but it is not a big deal as websites such as code.org let you know when this happens
This is what it looks like in code.org when there is no semicolon at the end of a line of code. When there is it should look like this.
You should be able to see the number and that indicates the line of code your on and that you have no errors. The yellow caution signs indicate a minor error in your code such as a slightly incorrect syntax or a missing semicolon however if there is a large red square that indicates a big error in your code that will cause it to not run.
Can you spot the error? The problem is there is no parenthesis around the quoted text hello world. This causes the computer to think you are typing out one solid command that says in console log hello world as opposed to in console log display text hello world.
The final part of this lesson will go over the first place we will apply our coding knowledge, The console log. The console log is essentially a separate mini code player that can be used primarily to display text. We can use the variable operator console.log () to display numbers and console.log (“”) to display text or strings. Strings are just a fancy way of saying text that is used by computers. Strings need the quotation marks to identify themselves because they work differently than numbers.
These are the exact same code using the division operator however one is a number being divided the other is a string. The string cannot be divided so this becomes the output for the code
It becomes 10 which is the correct output for out first line of code but it becomes NaN or not a number for our second line of code. This is because strings can only be used with the addition operator. But I will get into that next lesson.
Thank you all for reading I hope you enjoyed and as always feel free to swing by my YouTube channel where I just uploaded a new video!