JS (variable types and calculation questions in interviews)

JS (variable types and calculations)

Question 1. What types can be obtained using typeof in JS?  

Question 2. When to use === When to use ==? 

Question 3. What are the built-in functions in JS?

Question 4. JS variables are classified into those types according to their storage methods, and describe their characteristics?

Topic 5. How to understand JSON

1. Variable type (storage method)

1. Value type

 The value type stores the value in a specific location, a stores 100, a is assigned to b, then b stores 100, changes the location of a to 200, but the location of b still stores 100.

2. Reference type

In the reference type, assign a to an object, the object exists in another place, and the memory location of a points to this place through a pointer.

In line 2, when assigning a to b, it actually defines a, and then the pointer of a points to b. After lines 1 and 2 are executed, both a and b point to the object age:20. When line 3 is executed, age The value of has become 21, and a also points to this object, so its value is also 21.

Reference types: objects, arrays, functions (features: you can add properties without restrictions. In order to let properties share memory space, the "reference" method is used)

Question 4. JS variables are classified into those types according to their storage methods, and describe their characteristics? see above

3. typeof operator

6 forms: 1.undefined 2.string 3.number 4.boolean 5.object 6.function (function)

(typeof can only distinguish the data type of the value type [the first 4 lines], and cannot distinguish the data type of the reference type)

Question 1. What types can be obtained by using typeof in JS? see above

2. Variable calculation (forced type conversion)

1. String concatenation

10 is a number, '10' is a string

2. == operator

== will perform forced type conversion, and there is a tendency to make the front and back equal

0 == ' ' / null == undefined (will be converted to false)

Question 2. When to use === When to use ==? 

=== No type conversion at all! Except for the above cases, all others use ===

3. if statement

 

4. Logical operations

1.将 10 转换成 true

2.将‘ ’转换成  false

3.window.abc 为 undefined ,经过 ! 变为 true

判断方法

 题目3.JS 中有哪些内置函数?(数据封装类对象)

不考虑浏览器环境和运行环境,但就 JS 这个语言所内置的函数如图所示

题目5.如何理解 JSON

JSON 是一种数据格式 ,也是JS 内置对象,常用 API 如图所示

1.JSON.stringify 将对象转换成字符串

2.JOSN.parse 将字符串转换成对象

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325209676&siteId=291194637