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 changeArrow 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?