Sintassi

Regole di sintassi JavaScript moderne seguendo ES6+ e best practices PANDEV.

πŸš€ ES6+ Features

Dichiarazioni di Variabili

❌ Evitare:

// bad - var has function scope and hoisting issues
var user = 'John'
var users = []

// bad - no re-assignment but used let
let API_URL = 'https://api.example.com'

// bad - re-assigning const
const currentUser = null
currentUser = user // TypeError

βœ… Preferire:

// good - use const by default
const API_URL = 'https://api.example.com'
const users = []

// good - use let only when reassignment is needed
let currentUser = null
let retryCount = 0

// good - const with objects/arrays (contents can change)
const user = {
  name: 'John',
  age: 30
}
user.age = 31 // OK - object contents can change

Arrow Functions

❌ Evitare:

βœ… Preferire:

Template Literals

❌ Evitare:

βœ… Preferire:

Destructuring

❌ Evitare:

βœ… Preferire:

Spread Operator

❌ Evitare:

βœ… Preferire:

πŸ”§ Control Flow

Conditional Statements

❌ Evitare:

βœ… Preferire:

Loops and Iteration

❌ Evitare:

βœ… Preferire:

🎯 Modern Syntax Features

Optional Chaining

❌ Evitare:

βœ… Preferire:

Nullish Coalescing

❌ Evitare:

βœ… Preferire:

Object Property Shorthand

❌ Evitare:

βœ… Preferire:

πŸ”„ Best Practices

Function Declarations

❌ Evitare:

βœ… Preferire:

Return Statements

❌ Evitare:

βœ… Preferire:

Queste regole di sintassi garantiscono codice JavaScript moderno, leggibile e performante seguendo gli standard PANDEV.

Last updated

Was this helpful?