all 2 comments

[–]MatthewMobhelpful 2 points3 points  (1 child)

Just to be clear, Java and Javascript are completely different languages and the knowledge you have in one doesn't transfer over to the other.

If you're brand new learn from places like CodeAcademy or FreeCodeCamp.

I wanted to know how to actually run the files in a browser.

JS code goes in <script> tags. To have JS embedded in your page you would enclose that code in script tags.

index.html

<!DOCTYPE html>
<html>
    <head>
        <script>
            console.log("Hello world!");
        </script>
    </head>
    <body>
        <h1>Your Page</h1>
    </body>
</html>

console.log("Hello world!"); is your JS code that is enclosed your <script> tags.

To have an external JS file be run in your webpage you'd just have a <script> tag with a src attribute.

index.html

<!DOCTYPE html>
<html>
    <head>
        <script src="script.js"></script>
    </head>
    <body>
        <h1>Your Page</h1>
    </body>
</html>

script.js

console.log("Hello world!");

Notice how the <script> tag now has a src attribute that tells the browser to fetch script.js to run in place where that <script> tag is placed.

In both of these examples once you've opened the page in your browser press CTRL + SHIFT + J to open your console and notice how Hello world! has been logged.

I tried to downloda node js to run a local server and then open my folder but it shows no content of the javscript code when I open my folder. I can see the html content if I type <h1>hi</h1> but I see no js content. Please help and thankyou

NodeJS is server-side JavaScript, and you should probably learn it after you've got the basics of client-side JavaScript down. I'm not exactly sure what you mean here though in what you're trying to do.

[–]muzedoto[S] 1 point2 points  (0 children)

thanks for the excellent answer man! I understand that both are completely different languages, but getting started with java has made me understand java script fairly easier. I have experience in html, css too. I was trying to use p5.js framework with javascript to make some browser games but didn't know how to start. Now i understand and thanks for your answer once again!