What you can do with this JavaScript editor
JavaScript is the programming language built into every web browser. It makes pages interactive, and through Node.js it also runs servers, build tools and command-line scripts. This editor is a quick place to write or tidy JavaScript in the browser, with highlighting, autocomplete, find and replace, and a download that saves your work as a .js file.
It suits small jobs: drafting a function before it goes into a project, cleaning up a snippet for a code review or blog post, or keeping notes while you learn. The editor doesn't execute code. There's no console and no preview pane, so nothing you type runs on this page.
As you type, the editor suggests keywords, common snippets such as a for loop template, and names of variables and functions already declared in your file. Brackets and quotes close automatically, and matching brackets light up when the cursor sits next to one.
Try it with this snippet
const orders = [
{ id: 1, total: 42.5, status: "paid" },
{ id: 2, total: 18, status: "refunded" },
{ id: 3, total: 7.25, status: "paid" },
];
const paidTotal = orders
.filter((order) => order.status === "paid")
.reduce((sum, order) => sum + order.total, 0);
console.log(`Paid: ${paidTotal.toFixed(2)}`); // Paid: 49.75
console.log(orders.at(-1)?.status ?? "none"); // paid
It uses array methods, an arrow function, a template literal, at(-1) for the last element, optional chaining and nullish coalescing. The comments show what each line prints when run.
Running your JavaScript
You have two easy options, depending on whether the code is meant for a browser or for Node.js.
In a browser. Open developer tools with F12 (or Cmd+Option+J in Chrome on macOS), switch to the Console tab, paste your code and press Enter. This works for anything that doesn't need a specific web page. For code that touches the DOM, put it in a <script> tag inside an HTML file and open that file in the browser; the HTML editor is useful for that.
With Node.js.
- Install Node.js from nodejs.org if you don't have it.
- Click Download to save the file. It arrives as
script.js. - In a terminal in that folder, run
node script.js.
To check syntax without running anything, use node --check script.js. If your file uses import and export, either rename it to .mjs or add "type": "module" to a package.json, since Node treats plain .js files as CommonJS by default.
Gotchas the editor won't catch
| Pitfall | What happens | Fix |
|---|---|---|
== instead of === |
Loose equality converts types first, so 0 == "" and null == undefined are both true |
Use === unless you specifically want coercion (MDN equality comparisons) |
return on its own line |
Automatic semicolon insertion ends the statement there, so the function returns undefined |
Keep the returned value on the same line as return, as defined in the ECMAScript ASI rules |
Expecting 0.1 + 0.2 === 0.3 |
Numbers are IEEE 754 doubles, so the sum is 0.30000000000000004 |
Compare with a small tolerance, or work in whole cents for money |
Mutating a const object |
const stops reassignment, not changes: items.push(4) still works |
Use Object.freeze() if you need a read-only object |
typeof null |
Returns "object", a quirk kept for backward compatibility |
Test with value === null |
Where to go next
The JavaScript course covers the language from variables to async code, and the JavaScript cheat sheet is a fast syntax reference. For background on the language itself, see the JavaScript overview. If you work with patterns in strings, test them in the regex tester, and for typed code switch to the TypeScript editor.
Last updated