CodeNest

Variables and template literals

Declare variables with const (cannot be reassigned) or let (can be):

const name = "Sam";
let age = 25;
age = age + 1;

Common types: number, string, boolean, undefined, null, object. Check with typeof value.

Template literals use backticks and ${ } to embed expressions:

console.log(`${name} is ${age} years old.`);

Try it

Print exactly:

Sam is 25 years old.
In 10 years: 35
JavaScript in-browser
Next
Loading editor…

Press Ctrl/ + Enter or click Run to see the output here.