JavaScript Get Started

JavaScript - Get Started

1. VS Code

2. Node.js

In VS Code 

Create New file and rename it to index.html

! + Tab Key to generate basic html code

In index.html We can Add JavaScript in <head> or <body> section but best practice to put at the end of </body> tag

// comment tag to Express Comment in JavaScript, Whatever code enter below double code’s // ignored by JavaScript Engine


console.log ('Hello World');


To view Developer tools in browser Ctrl + Shift +I or F12

log will log a message on console

This is called Inline style sheet

Hello World is a statement

All statement in JavaScript should terminate by semi colon;

What we have here in between in Single codes ' ' is called string

A string is a sequence of character

console.log ('Hello World')

<script></script> Script Element JavaScript code in between script element is called Inline Code.

In Real World there are thousands of codes, we need to extract and separate JavaScript code from html & CSS code

For Example: Think about house in bedroom you have your bed and clothes, you don't store clothes in kitchen this is called separation of concerns, we have to apply the same principle in programming.

So, we want to separate html, with all other content from JavaScript

JavaScript Which is all about behaviour

1. How should your webpage behave?

2. What should happen when you hover your mouse over given element 

May be something should popup

Something should hide

3. So, we use JavaScript to implement behaviour

Create Separate file for JavaScript in VS Code by creating new file and rename to index.js

Enter simple console.log ('Hello World'); in index.js no need to Enter inside <script></script> Element

To refer JavaScript file in index.html


<script src="index.js"></script>


How to execute above same code in node.js

Open CMD Prompt on the folder where index.js is created 

Now in command prompt type node index.js

Now Hello World will display.

You will receive the same message which was received in browser console.

So, Node is Program that include Google V8 JavaScript engine

In VS Code there is an Integrated Terminal 

To Open Terminal in VS Code Under Tab>View Menu>Terminal 


                                                                          Ctrl + I

Post a Comment

Share your thoughts here

Previous Post Next Post