zoukankan      html  css  js  c++  java
  • [javascript|基本概念|Underfined]学习笔记

    Underfined类型的值:underfined(只有一个)

    1/声明未初始化

    e.g.:var msg;-->msg == underfined:true

    2/申明并值初始化为underfined

    e.g.:var msg = underfined;-->msg == underfined:true

    3/未声明

    e.g.:msg;-->Error:msg is not defined

    只能用typeof检测

    判断是否声明或未申明

    try{

      if(msg == underfined || msg){

        console.log("exist");

      }

    }catch(e){

      console.log("not exist");

      console.log(e);

    }

    try{

      msg in window;

      console.log("exist");

    }catch(e){

      console.log("not exist");

    }

    建议:一般值为underfined的变量不需要显式赋值,但是只要声明变量,就初始化是定义变量最好的习惯。

  • 相关阅读:
    find the most comfortable road
    Rank of Tetris
    Segment set
    Codeforces Round #380 (Div. 2)D. Sea Battle
    A Bug's Life
    Is It A Tree?
    N皇后问题
    符号三角形
    2016 ICPC总结
    Sudoku Killer
  • 原文地址:https://www.cnblogs.com/bsj2016/p/5437923.html
Copyright © 2011-2022 走看看