Commenting & Variables
Last updated
Last updated
A comment is a way to leave notes for anyone who reads the code.
In JavaScript, the pattern //
is reserved to create a single line of code that will be converted to a comment.
The JavaScript compiler will always ignore a line of comment when it sees the pattern of //
in the beginning of the line.
The JavaScript compiler which translate our written instruction to a language that a computer can understand will translate the JavaScript code in order from top to bottom.
The code will then execute its instruction from top to bottom.
Variables are named placeholders that allow a programmer to attach important data that a program would need to an easy label that can be used to reference later.
start with lowercase letters
labels that have multiple words are either camelCased
or use under_scores
labels cannot be the same as the built-in keywords in Java
labels should not be ambiguous let a = "Park";
is less descriptive than let last_name = "Park";
Comment:
This is a single-line comment. Comments are used to leave notes or explanations in your code. They are ignored by the JavaScript engine and do not affect the execution of the program.
Variable Declaration and Initialization:
let
is a keyword used to declare a variable. In this case, the variable is named greeting
.
The variable greeting
is assigned the string value "Hi, how are you?"
.
Output to Console:
console.log()
is a function that prints the value of greeting
to the console.
When this line is executed, it will output: Hi, how are you?
So, when you run this program, it will display the message "Hi, how are you?"
in the console.
Note: You cannot create the same variable twice.
If you wanted to change/update the value stored in a variable, you can just do a variable update.
You are allowed to re-reference a variable created and assign a new value when switching its value.
WARNING: the program will not remember its previous value.
Variables (Link)