- Using console tab of web browsers
- Using Node.js
- By creating web pages
1. Using Console Tab of Web Browsers
- Open your favorite browser (here we will use Google Chrome).
- Open the developer tools by right clicking on an empty area and select Inspect. Shortcut:
- Install the latest version of Node.js.
- Install an IDE/Text Editor like Visual Studio Code. In VS code, create a file > write JS code > save it with .js extension.
- Open up the terminal/command prompt > navigate to the file location > type
node hello.js> hit enter.
- You will get output on the terminal.
node and press enter. Then you can start writing JS code.
By Creating Web Pages
- Open VS Code > Go to File > New File > Save it with .html extension. For example,
- Copy this doctype (minimum valid HTML code) and save it in the file.
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Programiz</title> </head> <body> <script src=""></script> </body> </html>
- Similarly create a JS file, write the following JS code and save it with .js extension like
- From inside the HTML file, we need to link the
main.jsfile to use it. You can achieve that by adding the following code in
- Open the
main.htmlfile using a browser.
- To check if our JS code ran or not, Right click on the web page > Inspect > Choose console tab.