Javascript in html

Can I run javascript program in html code in visual studio? I have installed node js also.

visual studio or visual studio code? note that they are two different programs

You can write script tags inside your html file and write code in it, or link to a JavaScript file, yes

or you can run a JS file with node directly

I have visual studio code

You can write some HTML code and open the file in a browser, yes. Strictly speaking you can’t run JavaScript code in HTML in VSCode though: VSCode is a program for writing text. You write some text and you save it as a file. The program that understands HTML files is a web browser.

You can install a plug-in that will open the browser automatically so that you don’t have to, say, double click on the HTML file you’ve written so it opens. For example, a live server plugin that automatically reloads the browser when you make changes to files – Live Server - Visual Studio Marketplace

No I have node js too…also the tutorials I am studying they are providing JS inside html tags…that’s why I am asking in VS code anyway can I run JS code inside html tags?

Write the HTML file with VS Code, then open it with your web browser.

yes you can run
in program htmlstrong text

Yes, that’s the primary way JS code is used, either inline in a script tag

  // JavaScript goes here

Or by giving the script tag the URL of a file that just contains JS:

<script src="some-javascript.js"></script>

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.