After a period of sorting, I have selected interview questions to share with my friends~ Let's take a look at the following interview questions!
first question:
var lowerCase = /^[a-z]+$/; console.log(lowerCase.test(null));//true console.log(lowerCase.test());//true
Friends who are familiar with regular expressions in javascript should all understand that this is a regular expression that validates any a to z. The test() method in the regular expression verifies a string, and null is an object, which is forced to be converted to a string when using the test() method, so it is true; when the verification value is empty, it is forced to be converted to test (' undefined'), so also true;
Second question:
var a = /123/; var b = /123/; console.log(a==b);//false console.log(a===b);//false
This question requires a certain understanding of object. The object is compared by the memory address pointed to by the pointer. As long as the memory address is different, both are false; in this question, both a and b are regular objects, pointing to a and b respectively, So the memory pointed to is not the same, it is false;
Third question:
console.log(1<2<3,3<2<1);//true,true
Whether it is '<', or '>', it is operated from left to right; 1<2----true, true<3 will force true to convert to 1, that is, it becomes 1<3, so it is true ;
Similarly, 3<2 is false, and false<1 is converted to 0<1, so it is true;
Fourth question:
var arr = Array(3); arr[0] = 2; arr.map(function(elem){ return '1'; })//['1',empty*2]
First of all, we need to understand the usage of map() function,
array.map(function(currentValue,index,arr){},thisValue);①, each element in the array will execute this function, the function must pass
②, function parameters: currentValue is a required parameter , the value of the current element; index: optional, the index value of the current element; arr: optional, the array object to which the current element belongs
Fifth question:
function foo() } var oldName = foo.name; foo.name = "bar"; console.log(oldName,foo.name)//foo,foo
Note: The function instance will have a built-in name attribute. Because it is rarely used in development, many small partners do not know the existence of this thing. This attribute is read-only and cannot be modified. No matter how it is assigned, it is invalid. .
Question 5: Many friends must have used the method in Math. Next, let’s take a look at the interesting question. I didn’t find it before, so I will share it with you now~
var min = Math.min (); var max = Math.max(); min < max
Comparing the minimum value and the maximum value, I believe that many friends feel like they will return true like stinky, but it is not true~
Math.min() and Math.max(), these two methods, if you pass them multiple arguments, are known to return the max/min value among them. However, if no parameters are passed, there will be a very interesting phenomenon: the return value of Math.min() is Infinity (positive infinity), and the return value of Math.max() is -Infinit (negative infinitesimal). So, the correct comparison result is Math.min() > Math.max().
Okay, my friends, that's all for today's interview questions~~~