--- lang: ja-jp breaks: true --- # TypeScript で null undefined empty を否定した場合の動作 2021-05-15 ```typescript= 'use strict'; if (!null) { console.log("not null."); } if (null != true) { console.log("null is not true."); } if (!"") { console.log("not emply."); } // ↓compile error. //if ("" != true) //{ // console.log("emply is not true."); //} if (!undefined) { console.log("not undefined."); } if (undefined != true) { console.log("undefined is not true."); } console.log("exit."); ``` ```shell= $ ts-node null_test.ts not null. null is not true. not emply. not undefined. undefined is not true. exit. ``` ###### tags: `TypeScript` `null` `undefined` `empty` `ts-node`