Today, I will solve this problem for you by explaining these concepts in the easiest possible manner.
The agenda of the article will be:
- Learning how to print statements and add comments
- How to declare variables using
All of the programming languages in the world can be classified into two categories viz. Compiled Languages and Interpreted Languages.
In a compiled language, we build a compiled code from the program using a compiler and the target machine directly runs the compiled program.
In an interpreted language, the program is not compiled and directly translated by the target machine. Instead, a different program, aka the interpreter, reads the code line by line and executes the code in real-time.
For example, let’s say you are trying to make Dalgona coffee at home. But the recipe shared by your friend is in ancient Latin. Since you don’t know Latin, you can make coffee from the recipe using either of the two below approaches.
You will get the recipe translated into English for using a translation service or program. Then you can use the English version of the recipe directly to make Dalgona coffee at home. This is similar to how you would run a program through a compilation service to get a source code that can be used directly by a machine to run a specific task.
The Second approach could be to search for a friend who knows ancient Latin, get him/her over to your house and ask him/her to translate the recipe line by line while you make the coffee. This is similar to how we use an interpreter to go through the program code line by line while executing a specific task.
You can learn more about compiled and interpreted languages from the article below from which the above example is taken:-
repl in the editor and continue with our coding part.
console.log statement. This will print the value in the browser console usually and in the current case in the console present on the right-hand side of the repl.
console.log("Hello everyone"); // Console output: Hello everyone
console.log("\"Hello everyone\""); // Console output: "Hello everyone"
We can use
// This is a single line comment
For multiline comments, we start the comment with
/* and end the comment with
*/ as shown below:-
/* This is a multiline comment We can add multiple lines in the comment */
Variables are the names we give to computer memory locations in which store values for a specific purpose.
The declaration of a variable using the
let keyword can be done as shown below:-
let studentName = "Joe"; console.log("The name of my student is "+studentName); //Output:- The name of my student is Joe
Note:- We can either use
+ symbol or
We generally use the
let keyword when there is a need to redefine or redeclare our variables. In simpler terms, if the value stored in a variable needs to change at some time in future in our program, we make use of the
Let’s learn this with an example:-
let studentName = "Joe"; console.log("The name of my student is "+studentName); studentName = "John"; console.log("The name of my student is "+studentName); /* Output:- The name of my student is Joe The name of my student is John */
Here we redefined the
studentName variable to store a new value
John after storing the initial value as
Joe. In such cases, we make use of the
const keyword is used when a variable needs to store a fixed value which never changes during entire program execution.
Let’s understand this with an example:-
const pi = 3.14; console.log("Value of pi", pi);
When we define the value mathematical constant like
π in our program, we know that its value will not change during the entire program execution. So we define the value using the
Thank you for reading, If you have reached so far, please like the article, It will encourage me to write more such articles. Do share your valuable suggestions, I appreciate your honest feedback!
See you in my next article, Take care!!