underfined是var 变量没有赋值的情况,可用null覆盖

```内容

<!DOCTYPE html>

<html lang="en" xmlns:th="http://www.thymeleaf.org/">

<head>

    <meta charset="UTF-8">

    <title>Title</title>

    <base th:href="${#servletContext.getContextPath+'/'}">

</head>

<body>

<script>

    var username;

    document.write(username+"<br>");

    var username = null;

    document.write(username+"<br>");

</script>

 

</body>

</html>

 

```

结果

undefined

null