Engineer bro!
Sat Apr 09 2022 (3 months ago)
Engineer by mistake!
I am a software engineer by passion
You'll see the Hello World
example in many programming tutorials and we will start with Hello World
too.
Paste the below script into the browser console.
console.log("Hello World");
You will see Hello World
printed on the browser console.
Let's see elements of console.log("Hello World");
As you can see in the above example, console.log("Hello World");
have a total of five components. A combination of each of the components is making a statement that can be executed by the JavaScript engine.
The components are
console
.
log
"Hello World"
;
Let's see the components one by one
console
is an object provided by JavaScript run time. It gives access to the browser developer console and is used for debugging purposes.
Browser and developers both can print on the console. There is numerous formatting that can be applied while printing on the console, but that is out of the scope of this article.
. (dot) is an operator which is used to access properties and methods of the object. You'll learn about objects later in the packageName.
Let me explain to you the object, methods and properties in simple terms.
There is a milkman Rakesh in the town who used to deliver milk in the town. He has two children, Raushan and Avinash. Raushan used to deliver cow milk, whereas Avinash used to deliver Buffellow milk.
So, here Rakesh is an object, Raushan and Avinash are their properties and delivery is their method/function.
To access Raushan - Rakesh.Raushan
To access Avinash - Rakesh.Avinash
To deliver milk of cow - Rakesh.Raushan.deliver()
Similarly, console
is an object which provides access to the browser developer console and log
is a method of console
which can print on console.
log
is a method of console
object, which can print inputted data on console.
"Hello World"
is a string, you will learn about strings later in the packageName. This string will be inputted to the console to print.
;
semicolon is used to terminate the statement. Although it is not required, it is a recommended convention that you should terminate the statement.
© 2021 dsabyte. All rights reserved
Comments (0)