Home > Web Front-end > JS Tutorial > Undefined instance analysis in js

Undefined instance analysis in js

小云云
Release: 2018-02-26 13:58:24
Original
1696 people have browsed it

When we develop, we often encounter undefined situations. This article mainly shares with you a summary of undefined problems in js, hoping to help everyone.

 //1.变量声明了但是没赋值 解析器会给一个默认值 就是undefined
    var a;
    console.log(a);
    //2.数组中 某一项没有值 值是undefined
    var arr = [1, 2, 3];
    console.log(arr[10]);
    //3.形参接收不到值 接收到的就是undefined
    function fn(a, b) {
        console.log(b);
    }
    fn(1);
    //4.函数没有返回值 相当于返回了undefined
    console.log(fn(1, 2));
    //5.对象没有这个属性 非要获取这个属性的值 这个属性的值也是undefined
    var obj = {
        name: "zs",
        age: 18
    };
    console.log(obj.sex);
    //undefined都是解析器给的默认值
    //null一般都是程序员主动赋予的值
    var arr = [];
    arr.push();
Copy after login

Related recommendations:

Detailed explanation of the difference between undefined and null in JavaScript

php prompt undefined index solution

The above is the detailed content of Undefined instance analysis in js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template