JavaScript Syntax References

JavaScript syntax quick reference for common tasks, from MDN Web Docs. Every item below is clearly marked as a shortcut, command, or syntax reference.

Most Useful JavaScript Syntax References

JavaScriptSyntax

Log to Console

Code example
console.log(value)

Prints a value to the browser or Node console.

Learn More
JavaScriptSyntax

Declare a Constant

Code example
const name = "Ada";

Declares a variable that can't be reassigned.

Learn More
JavaScriptSyntax

Define a Function

Code example
function add(a, b) { return a + b; }

Defines a named function.

Learn More
JavaScriptSyntax

Arrow Function

Code example
const add = (a, b) => a + b;

Defines a short function expression.

Learn More
JavaScriptSyntax

If / Else

Code example
if (x > 0) { ... } else { ... }

Runs code depending on a condition.

Learn More
JavaScriptSyntax

Declare a Variable

Code example
let count = 0;

Declares a block-scoped variable that can change.

Learn More
JavaScriptSyntax

For Loop

Code example
for (let i = 0; i < 10; i++) { ... }

Loops a set number of times.

Learn More
JavaScriptSyntax

For...of Loop

Code example
for (const item of items) { ... }

Loops over the values of an array or iterable.

Learn More

More JavaScript Syntax References

Frequently Asked Questions

What does this JavaScript syntax reference cover?

It covers 39 common JavaScript patterns and examples, including Log to Console, Declare a Constant, Define a Function, Arrow Function, If / Else.

Can I copy the JavaScript examples?

Yes. Each reference page includes a copyable code example.

What affects these JavaScript examples?

Check the linked documentation for language or runtime version requirements. Libraries, file paths, terminal quoting and environment settings can differ across systems; no blanket platform compatibility is implied.