Kieran McCarthy
Kieran McCarthy

Reputation: 45

How do I run a javascript code

I have been given a code to run to analyse and I cannot find where to run it, I have tried google chrome but it is confusing the hell out of me and my friend told me note plus plus but im not sure how to open that or if that even works thank you for your help

Upvotes: 0

Views: 62

Answers (5)

FreakyOne
FreakyOne

Reputation: 431

You have 2 options to run a js code: Nodejs and any browser you want(I suggest google-chrome) Option 1(Nodejs):
First you must install nodejs. There are tons of tutorials on the net. Then open cmd/terminal and navigate to the javascript file. Then type node filename.js.
Option 2(browser):
first create an index.html file in the directory where the .js file is located. Then open it with any text editor(I suggest brackets) and enter the following code:

<!DOCTYPE html>
    <html>
        <head></head>
        <body>
            <script src="filename.js"></script>
        </body>
    </html>

Now save the file and close the editor. Click with the right button on the html file and the choose open with->google-chrome. If the js file have console.logs the press f12 while in the browser.

Upvotes: 0

phaberest
phaberest

Reputation: 3220

I suppose what you are asking is not how to run it, but how to learn it. Notepad++ is an editor you may use to write your code, then you can view and debug it in approximately any browser. Have a look on how to start learning JavaScript

Upvotes: 0

DerekW
DerekW

Reputation: 31

You can run it in the chrome dev tools console, or use something like https://repl.it/languages/javascript or https://jsfiddle.net/

Hope this helps.

Upvotes: 1

Berti92
Berti92

Reputation: 471

On chrome press F12 then open the tab console and here you can test your code

Upvotes: 0

Axnyff
Axnyff

Reputation: 9944

You can use Ctrl+Maj+J to directly go to the javascript console where you can paste that code.

You can also run it by using NodeJs

However, you really should avoid running random code unless you know what it's doing.

Upvotes: 0

Related Questions