// Sample Javascript Code

function add(x, y) {
    var resultString =  "The result of your math is: ";
    var result = x + y;
    return resultString + result;
}

var addResult = add(3, 2);
console.log(addResult);

About This JavaScript Editor

JavaScript is the only programming language browsers run natively, and since Node.js it runs servers, build tools and desktop apps as well. It is dynamically typed, prototype-based, and single-threaded with an event loop - a combination that makes it forgiving to start with and full of sharp edges once you go deeper.

The editor highlights ES2015 and later syntax, matches brackets, and auto-indents. It edits code; it does not execute it, so nothing you paste here runs.

Modern JavaScript syntax reference

JavaScript syntax reference
Syntax What it does
const x = 1; let y = 2; Block-scoped bindings. Never use var in new code - it is function-scoped and hoists.
const f = (a, b) => a + b; Arrow function. Inherits this from the enclosing scope instead of binding its own.
`Total: ${a + b}` Template literal with interpolation. Backticks, not quotes.
const { a, b = 2 } = obj; Destructuring with a default value.
const merged = { ...a, ...b }; Spread. Later keys win, so b overrides a.
obj?.a?.b ?? "default" Optional chaining short-circuits on null or undefined; ?? falls back only on null/undefined, unlike ||.
await fetch(url) Inside an async function, or at the top level of a module.
arr.map(f).filter(g).reduce(h, 0) The three array methods that replace most loops.

Things that catch people out

  • Equality. == coerces types, so "1" == 1 is true and null == undefined is true. Use === unless you specifically want coercion.
  • this. In a regular function, this depends on how the function was called. In an arrow function it is fixed at definition. Most "this is undefined" bugs are a regular function where an arrow was needed.
  • Floating point. 0.1 + 0.2 === 0.3 is false, in JavaScript as in every IEEE 754 language. Compare with a tolerance, or work in integer cents.
  • Async in loops. forEach does not await. Use a for...of loop with await, or Promise.all with map.
  • Sorting numbers. [10, 9, 1].sort() gives [1, 10, 9] because the default comparator is lexicographic. Pass (a, b) => a - b.

Your Code Never Leaves Your Browser

The editor is JavaScript running in this tab. Nothing you type is posted to a server, stored, logged or associated with you, and there is no account and no autosave. That makes it safe to paste a snippet from a private codebase in order to read it with highlighting. The trade-off is that nothing persists either — refresh the page and your content is gone, so copy anything you want to keep.

Frequently Asked Questions

Can I run JavaScript in this editor?

No. This is an editor, not a runtime - it gives you highlighting, indentation and bracket matching, and nothing is executed or sent anywhere. To run code, use your browser's devtools console, Node.js locally, or a sandbox designed for execution.

Is JavaScript the same as Java?

No, and the similar name is an accident of 1995 marketing. They differ in typing, memory model, concurrency and syntax. The only real overlap is C-influenced curly-brace syntax.

What is the difference between null and undefined?

undefined means a variable exists but has no value assigned, which is what you get from a missing property or a parameter that was not passed. null is an explicit "no value" that you assign deliberately. Both are falsy, and both are caught by the ?? operator.

Editors for Other Languages

Same editor, configured for a different language, each with its own syntax reference.