NULL




Nullo
In JavaScript null e' "niente". Dovrebbe essere qualcosa che non esiste.

Sfortunatamente, in JavaScript, il tipo di dati di nulle' un oggetto.

Puoi considerarlo un bug in JavaScript che typeof nulle' un oggetto. Dovrebbe essere null.

Puoi svuotare un oggetto impostandolo su null:

Esempio
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
person = null; // Now value is null, but type is still an object


<!DOCTYPE html>
<html>
<body>

<h2>JavaScript</h2>

<p>Objects can be emptied by setting the value to <b>null</b>.</p>

<p id="demo"></p>

<script>
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
person = null;
document.getElementById("demo").innerHTML = typeof person;
</script>

</body>
</html>

Risultato = object

******************************************************************
Puoi anche svuotare un oggetto impostandolo su undefined:

Esempio
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
person = undefined; // Now both value and type is undefined










( null.html )- by Paolo Puglisi - Modifica del 17/12/2023