Skip to content

Latest commit

 

History

History
18 lines (11 loc) · 611 Bytes

what_happens_with_negating_an_array.md

File metadata and controls

18 lines (11 loc) · 611 Bytes

What happens with negating an array?

When you negate an array in JavaScript, it is first converted to a primitive value, which is true when the array is non-empty and false when the array is empty. Negating it results in false for non-empty arrays and true for empty arrays.

Example:

let arr = [1, 2, 3];
console.log(!arr);  // Output: false
arr = [];
console.log(!arr);  // Output: true

Tags: intermediate, JavaScript, Arrays