Modern JavaScript syntax and features
| Command | Description |
|---|---|
const x = 1 | Block-scoped, cannot reassign |
let y = 2 | Block-scoped, can reassign |
var z = 3 | Function-scoped (avoid) |
| Command | Description |
|---|---|
const fn = () => {} | No parameters |
const fn = x => x * 2 | Single param, implicit return |
const fn = (a, b) => a + b | Multiple params |
const fn = () => ({ key: value }) | Return object literal |
| Command | Description |
|---|---|
const { a, b } = obj | Object destructuring |
const { a: renamed } = obj | Rename variable |
const { a = 1 } = obj | Default value |
const [x, y] = arr | Array destructuring |
const [first, ...rest] = arr | Rest in array |
| Command | Description |
|---|---|
[...arr1, ...arr2] | Merge arrays |
{ ...obj1, ...obj2 } | Merge objects |
fn(...args) | Spread as function arguments |
| Command | Description |
|---|---|
`Hello ${name}` | String interpolation |
`Line 1\nLine 2` | Multi-line strings |
tag`template` | Tagged templates |
| Command | Description |
|---|---|
export const x = 1 | Named export |
export default fn | Default export |
import { x } from "./mod" | Named import |
import fn from "./mod" | Default import |
import * as mod from "./mod" | Import all |