Is there a way to create and run javascript in Chrome?

后端 未结 9 2162
生来不讨喜
生来不讨喜 2020-12-13 06:21

Is there a way, like an extension or application, in Chrome to create and run .js files in Chrome?

相关标签:
9条回答
  • 2020-12-13 07:20

    if you don't want to create an explicitly a js file but still want to test your javascript code, you can use snippets to run your JS code.

    Follow the steps here:

    1. Open Dev Tools
    2. Go to Sources Tab
    3. Under Sources tab go to snippets, + New snippet
    4. Past your JS code in the editor then run command + enter in Mac. You should see the output in console if you are using console.log or similar to test. You can edit the current web page that you have open or run scripts, load more javascript files. (Just note: this snippets are not stored on as a js file, unless you explicitly did, on your computer so if you remove chrome you will lose all your snippets);
    5. You also have a option to save as your snippet if you right click on your snippet.

    0 讨论(0)
  • 2020-12-13 07:22

    You should write in file:

    <script>
         //write your JavaScript code here
    </script>
    

    save it with .html extension and open with browser.

    For example:

    // this is test.html
    <script>
       alert("Hello");
       var a = 5;
       function incr(arg){
           arg++;
           return arg;
       }       
       alert(a);
    </script>
    
    0 讨论(0)
  • 2020-12-13 07:28

    Usually one uses text editor to create source files (like JavaScript). I use VisualStudio which have intellisence supprt for JavaScript, but any other editor will do (vim or notepad on Windows are both fine).

    To run JavaScript by itself you need something that can do that. I.e. on Windows you can directly run script from console using CScript script.js command. There are other ways to run JavaScript on Windows and other OS.

    Browsers (like Chrome) do not run JavaScript by itself, only as part of a page or extensions. It is unclear what one would expect of browser to do with JavaScript by itself.

    0 讨论(0)
提交回复
热议问题