[JavaScript] data types and variables

1. == comparison, === comparison

Pay special attention to the equality operator ==. When JavaScript is designed, there are two comparison operators:

The first is == comparison, which will automatically convert the data type and then compare. In many cases, very strange results will be obtained;

The second is === comparison, it will not automatically convert the data type, if the data type is inconsistent, return false, if consistent, then compare.

Due to a design flaw in JavaScript, do not useCompare, always stick with= Compare.

2. Object

A JavaScript object is an unordered collection of key-values, for example:

var person = {
    
    
    name: 'Bob',
    age: 20,
    tags: ['js', 'web', 'mobile'],
    city: 'Beijing',
    hasCar: true,
    zipcode: null
};

The keys of JavaScript objects are all string types, and the values ​​can be of any data type. The above-mentioned person object defines 6 key-value pairs in total, and each key is also called an attribute of the object. For example, the name attribute of the person is 'Bob', and the zipcode attribute is null.

To get the properties of an object, we use the object variable. property name method:

person.name; // 'Bob'
person.zipcode; // null

Guess you like

Origin blog.csdn.net/daxiangaifashi/article/details/123272428