So we use double slashes “//” and then whatever I put after double slashes won’t actually work.
So if I did something like 10+10 would be normally 20, but it just does not run it all.
I am also going to show you one more thing here which is clear my console method, type the word clear and follow it with open and close parentheses like this clear(), and hit enter, and all it will do is clear my console.
So clear itself is something called a method.
And when we hit enter, it will clear my console.
You can see a complete blank console in the below screenshot
So the first method we are going to touch on is called alert(), and alerts is actually a little bit noxious.
What it does, it pops up a message to the user.
It basically alert the user about something.
The syntax of the alert method is below:
Syntax: alert( ) ; Inside of the parentheses, we pass in something that we want to be alerted.
So, I can put a message as a string like “This is Alert Message!!”
So when I hit enter, I get annoying popup message says:
We can also do the mathematical operation in the alert method, you can see here in below example where we have declared two variable num and num1 then multiply and show in the alert method.
So if someone doesn’t have the console open, they will never see it print.
Here is the syntax of this console.log method below Syntax: console.log ( ); If I want to print something, we need to write console.log() and then write something inside parenthesis with opening and closing quotes.
So, you can notice here console.log() print up ‘Hello from the Asgard’ text.
The last method we are going to discuss here is Prompt and Prompt is really useful for us because it lets us get input from the user. So here is the syntax for Prompt method below.
Syntax : prompt ( ) ; So here is an example of prompt method
And when you hit enter you will see a pop up asking for something from the user.
And when we write the name and hit enter then we will get the name back in the console.
It does not do anything with name value ‘thor’ because we are not storing the values.
In this part of prompt we are going to tell you that how you can store a value with prompt, here we are going to declare a variable ‘userName’ and then going to store the value in this variable, now I am asking for some input from the user again.
Now a popup will show again and here you will write name:
Hit enter and then if I write userName , I can get the username Loki that had been stored this time.