How has boolean logic evolved in recent JS versions?

boolean logic, JavaScript evolution, JS versions, modern JS, boolean operations
This article discusses the evolution of boolean logic in JavaScript, highlighting changes and improvements in recent versions that enhance developers' capabilities.

    // Example of boolean logic evolution in modern JavaScript
    const isTruthy = (value) => !!value; // Double negation to coerce into boolean
    console.log(isTruthy(1)); // true
    console.log(isTruthy(0)); // false

    // Using nullish coalescing operator to provide default values
    const getValue = (value) => value ?? 'default'; 
    console.log(getValue(null)); // 'default'
    console.log(getValue(5)); // 5

    // Optional chaining for safe property access
    const obj = { nested: { key: 'value' } };
    const keyValue = obj.nested?.key; // 'value'
    const missingValue = obj.missing?.key; // undefined
    console.log(keyValue, missingValue); // 'value' undefined
    

boolean logic JavaScript evolution JS versions modern JS boolean operations