// Online JavaScript compiler to run JS code in the browser.
// Write and execute JavaScript code in this online editor.
function greet() {
console.log("Hello, Tutorsbot!");
}
greet();
Write JavaScript, press Run and read the console output, including console.table and console.error. Code runs on Node.js, so require(), fs and the other built-in modules work, and errors come back with the line and column that failed. Copy a share link when you want someone else to run it.
const orders = [
{ id: 1, customer: "Asha", total: 1200 },
{ id: 2, customer: "Ravi", total: 450 },
{ id: 3, customer: "Asha", total: 300 },
];
const byCustomer = orders.reduce((acc, o) => {
acc[o.customer] = (acc[o.customer] ?? 0) + o.total;
return acc;
}, {});
console.log(byCustomer);
console.log(JSON.stringify(byCustomer, null, 2));
Your code runs the way node script.js runs on your own machine. That decides what is available:
require(), and Node's built-in modules such as fs, path, crypto, util and events. Timers and promises work, so setTimeout and await inside an async function behave normally.document and window are undefined because there is no page. For DOM code, buttons and CSS, use the HTML, CSS and JavaScript editor, which runs your script in a live preview.require("lodash") or require("axios") fails with Cannot find module. Most of what lodash is used for in practice exists natively now: Object.groupBy-style grouping with reduce, structuredClone for deep copies and Array.prototype.toSorted for sorting without mutation.Scripts run as CommonJS. Write const fs = require("fs"), not import fs from "fs": an import statement stops the script with Cannot use import statement outside a module. For the same reason, await at the top level of the file is a syntax error. Wrap async code in a function and call it:
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
(async () => {
console.log("start");
await wait(300);
console.log("300 ms later");
})();If you want ES module syntax and types, the TypeScript compiler and the Deno runtime are one click away.
Everything you print appears in the output panel in the order it happened. console.log prints objects the way Node formats them, nested arrays included. console.table draws an array of objects as a table, which is the quickest way to check the result of a map or filter. Messages from console.error go to the error stream and show up with the errors.
When a script throws, the first lines of the trace are the useful ones. TypeError: Cannot read properties of null (reading 'foo') plus file0.code:5:6 means line 5, column 6, where a value you expected to be an object was null. ReferenceError: x is not defined is usually a typo or a variable used outside its block. There is no step debugger, so log the values just before the failing line and run again.
setInterval that is never cleared, or a while (true) loop, gets stopped, and you see no output.fetch exists, but requests fail because the runner is offline. Test API-handling code with a hard-coded JSON object instead.readline loads, but nothing arrives on standard input. Put test values in a variable.fs.writeFileSync can be read back in the same run, then disappear.Interview rounds for front-end and Node roles lean on the same small set of skills. Each of these fits in a few lines and runs instantly here:
reduce, as in the example above, then rewrite it with a for...of loop and compare.makeCounter() that returns a function, call it three times, and explain why the count survives between calls.debounce(fn, ms) with setTimeout and clearTimeout, then call it five times in a row and log how often fn runs.Promise.all and then Promise.race, and log which result comes back.0 == "", null == undefined and NaN === NaN, then explain each answer.Practising them here shows you the real output, which is what an interviewer asks you to predict.
Both, depending on when you look. Node's engine parses your script, starts running it with an interpreter, and compiles the functions that run often into machine code while the program is running. That is called just-in-time compilation. In practice it means there is no separate build step for plain JavaScript: a syntax error stops the script before the first line runs, and every other error appears only when that line executes.
Tools people call "JavaScript compilers", such as Babel, the TypeScript compiler or bundlers, do something else. They translate code into other JavaScript, for example modern syntax into older syntax, or TypeScript into JavaScript. You do not need any of them to run a script here.