if you don't want to explicitly create 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. Paste your JS code in the editor then run Command + Enter on a Mac, or Ctrl + Enter on Windows or Linux. 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.

Answer from РАВИ on Stack Overflow
🌐
Chrome Developers
developer.chrome.com › docs › chrome devtools › run javascript in the console
Run JavaScript in the Console | Chrome DevTools | Chrome for Developers
April 18, 2018 - Sometimes, you just want a code playground where you can test some code, or try out new JavaScript features you're not familiar with. The Console is a perfect place for these kinds of experiments. Type 5 + 15 in the Console.
🌐
CoderPad
coderpad.io › blog › development › javascript-debugging-in-chrome
A Beginner’s Guide to JavaScript Debugging in Chrome - CoderPad
June 5, 2023 - It also works as an excellent tool for debugging your front-end JavaScript. No longer will you have to rely on adding and deleting hundreds of console.log(“this is another debugging message”); to see what your code is doing. Instead, you can leverage tools like Chrome’s DevTools to see what your JavaScript is doing in real-time as you move around the screen.
🌐
LambdaTest
lambdatest.com › software-testing-questions › how-to-run-javascript-in-chrome-browser
How to Run JavaScript in Chrome Browser: A Quick Guide
Alternatively, click the three-dot menu in the top-right corner of Chrome, select "More tools," and then select the Developer tools option. When DevTools opens, go to the Console tab.
🌐
BrowserStack
browserstack.com › home › guide › how to run javascript in chrome browser
How to Run JavaScript in Chrome Browser | BrowserStack
April 4, 2025 - Seamless Integration: JavaScript runs effortlessly in Chrome, working smoothly alongside HTML and CSS to create dynamic and interactive web applications. Performance Optimization: Chrome’s V8 JavaScript engine ensures faster script execution, optimizing web applications for better speed, responsiveness, and efficiency. Real-Time Testing: Chrome’s Developer Console allows developers to instantly execute and modify JavaScript code, making it easy to test scripts and see results without reloading the page.
🌐
BrowserStack
browserstack.com › home › guide › how to test javascript in browsers (with 5 methods)
How to test JavaScript in Browsers (with 5 Methods) | BrowserStack
March 28, 2025 - Learn to test JavaScript code in browsers with effective online tools such as JSFiddle, BrowserStack, CodePen, JSBin, & Liveweave.
🌐
BrowserStack
browserstack.com › home › guide › how to run javascript code in a browser?
How to Run JavaScript Code in a Browser? | BrowserStack
November 26, 2024 - Open Chrome → Press Ctrl + Shift + I (Windows) / Cmd + Option + I (Mac). Select Console. ... Press Enter. ... Open console with Option + Cmd + C. ... Press Enter. This guide explains how to run JavaScript code in different browsers and test ...
Find elsewhere
🌐
Codecademy
codecademy.com › article › running-javascript-in-the-browser-console
Running JavaScript in the Browser Console | Codecademy
As we can see, the console provides a quick and convenient way of running any JS code in the browser, whether independent of or directly related to the page content. If any edits are made to the page, the changes are temporary and will be gone upon refreshing, which works great for testing purposes when you don’t want to modify the actual code.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-run-javascript-in-chrome-browser
How to run JavaScript in Chrome Browser ? - GeeksforGeeks
November 13, 2023 - The following steps will assist you in including javascript in the Google Chrome browser be it through the use of a console in the browser for fast tests and debugging on complex web applications involving Java script integrated into HTML documents.
🌐
LambdaTest
lambdatest.com › home › blog › best 13 tools to test javascript code
Best 13 Tools To Test JavaScript Code | LambdaTest
October 31, 2023 - Right-click the element you want to inspect. Then click “Inspect,” which will launch the Chrome developer tools where you can test and debug the JavaScript code.
🌐
Playwright
playwright.dev
Fast and reliable end-to-end testing for modern web apps | Playwright
Cross-language. Use the Playwright API in TypeScript, JavaScript, Python, .NET, Java. Test Mobile Web. Native mobile emulation of Google Chrome for Android and Mobile Safari.
🌐
Google Support
support.google.com › adsense › answer › 12654
Allow JavaScript in your browser - Google AdSense Help
This article describes how to allow JavaScript in Google Chrome, which is required to display some media, including some Google ads. It also provides links to the documentation to turn on, activate, o
🌐
YouTube
youtube.com › watch
How To Run JavaScript In Google Chrome | Chrome Developer Tools - YouTube
When you're writing JavaScript in a Text Editor, it can be frustrating to constantly switch back and forth between the editor and your browser to see the out...
Published   August 19, 2024
🌐
BrowserStack
browserstack.com › home › guide › how to debug javascript in chrome?
How to Debug JavaScript in Chrome? | BrowserStack
May 30, 2025 - Learn how to debug JavaScript in Chrome using Chrome Devtools. Test on real browsers and devices with BrowserStack Live.
🌐
Enable JavaScript
enable-javascript.com
How to enable JavaScript in your browser and why
Instructions on how to enable (activate) JavaScript in web browser and why.
🌐
WhatIsMyBrowser.com
whatismybrowser.com › detect › is-javascript-enabled
Is JavaScript enabled? - WhatIsMyBrowser.com
June 26, 2024 - Nearly all websites need Javascript enabled these days, are you sure if you've got it enabled? This website will tell you if you have JavaScript enabled.
🌐
DZone
dzone.com › coding › javascript › how to test javascript code in a browser
How to Test JavaScript Code in a Browser
May 11, 2022 - Check out six popular tools and techniques for performance testing and debugging your application's JavaScript code in a browser, like JSFiddle and CodePen.