27 JS Questions

Source: Internet
Author: User


Begin
Original URL: http://javascript-puzzlers.herokuapp.com/
This article is the topic from the above URL, parsing is written by oneself

1. ["1", "2", "3"].map (parseint)
A ["1", "2", "3"] B [0,1,3] C [+] D Other
Select D ohter that is [1,nan,nan]:p arseint ("string", Redix), Redix represents the cardinality of the number to parse. The value is between 2 and 36, which is the binary number, and the map function passes in 3 parameters (Item,index,array), so [parseint ("1", 0), parseint ("1", 1), parseint ("1", 2)] When Redix is 0 o'clock, The default decimal, if it starts with "0x" or "0X", will be base 16.

2. [typeof null, NULL instanceof Object]
A ["Object", False] B [Null,false] C ["Object", True] D other
Select a null type is an object, typeof is a type that shows NULL, but NULL is not a data type with object Nature null Instanceof object is False
3. [[3,2,1].reduce (Math.pow), [].reduce (MATH.POW)]
A error b[9,0] C[9,nan] d[9,undefined]
Select A [9, error] [2,3].reduce (MATH.POW) =2^3=8


4. var val = ' Smtg ';
Console.log (' Value is ' + (val = = = ' Smtg ')? ' Something ': ' Nothing ');
Answer: Something
Parse: ' Value is ' + (val = = = ' Smtg ') is string true, so print something


5.
var name = ' world! ';
(function () {
if (typeof name = = = ' undefined ') {
var name = ' Jack ';
Console.log (' Goodbye ' + name);
} else {
Console.log (' Hello ' + name);
}
})();
Answer: Goodbye Jack parsing: If there are also variable declarations in advance

6.
var END = Math.pow (2, 53);
var START = END-100;
var count = 0;
for (var i = START; I <= END; i++) {
count++;
}
Console.log (count);
A: Count will enter an infinite loop 2^53 too large, start no matter how much plus one equals end

7.
var ary = [0,1,2];
ARY[10] = 10;
Ary.filter (function (x) {return x = = = undefined;});
Answer: [] Parse: Filter will jump directly to the number of non-existent parts of the value, so the value meets the requirements

8.
var = 0.2
var one = 0.1
var eight = 0.8
var six = 0.6
What are the following results?
[Two-one = = one, Eight-six = = one]
Answer: [True,false] two-one=0.1 0.8-0.6=0.20000000000000007 0.1+0.2=0.30000000000000004

9.
function ShowCase (value) {
Switch (value) {
Case ' A ':
Console.log (' Case A ');
Break
Case ' B ':
Console.log (' Case B ');
Break
Case undefined:
Console.log (' undefined ');
Break
Default
Console.log (' Do not know! ');
}
}
ShowCase (New String (' A '));
A: ' does not know! ' switch uses = = =, new String (' A ') is the object
10.
function ShowCase2 (value) {
Switch (value) {
Case ' A ':
Console.log (' Case A ');
Break
Case ' B ':
Console.log (' Case B ');
Break
Case undefined:
Console.log (' undefined ');
Break
Default
Console.log (' Do not know! ');
}
}
ShowCase2 (String (' A '));
Answer: There's nothing to say case a
11.
function isodd (num) {
return num% 2 = = 1;
}
function IsEven (num) {
return num% 2 = = 0;
}
function Issane (num) {
return IsEven (num) | | IsOdd (num);
}
var values = [7, 4, ' + ',-9, Infinity];
Values.map (Issane);//? Return array yes?
Answer [True,,true,true,false,false] -9%2 is-1, ' 13 '%2 will automatically transition to number,infinity%2 to Nan
12.
parseint (3, 8)
parseint (3, 2)
parseint (3, 0)
Answer: [3,nan,3] said above


Array.isarray (Array.prototype)
Answer: True array prototypes are also arrays


14.
var a = [0];
if ([0]) {
Console.log (A = = true);
} else {
Console.log ("Wut");
}
A: false parsing: in if ([0]) as a Boolean value of True,[0]==true as 0 is false


15. []==[]
A: False parsing is not good to know: https://www.zhihu.com/question/29615998


16.
' 5 ' + 3
' 5 '-3
A: ' 53 ', 2 ' + ' to make 3 into a string, but '-' to convert the string to a number exp:-' 223 ' for-223


17.1 +-+ + +-+ 1
A: 2 seems to be no mystery of 1 +-+ + +-+-1 for 0 see the final symbol is added or minus


18.
var ary = Array (3);
ary[0]=2
Ary.map (function (elem) {return ' 1 ';}); /? The returned array is?
Answer: [1,,] parse: The map function skips the part with no value


19.
function sideffecting (ary) {
Ary[0] = ary[2];
}
function Bar (a,b,c) {
c = 10
sideffecting (arguments);
Return a + B + C;
}
Bar (1,1,1)
Answer: 21 Analysis: In sideffecting (arguments); input console.log (arguments); you will find that the print out {' 0 ': 10, ' 1 ': 1, ' 2 ': 10},
The arguments object is a collection of parameters, like an array but not an array, in the bar function can initially be considered to change 3 times, the arguments input is {' 0 ': 1, ' 1 ': 1, ' 2 ': 10} through the sideffecting function {' 0 ': 10, ' 1 ': 1, ' 2 ': 10} so a=10,b=1,c=10.


var a = 111111111111111110000,
b=1111;
A + b;
Answer 111111111111111110000: The accuracy problem in JS affects both decimal and large numbers, but if B = 111111111111111111111, then the result a+b is 222222222222222230000


var x = [].reverse;
X ();
Answer: Window search analysis: []. Reverse will return this, and if no explicit sink object is called, it defaults to this aka window

Number.min_value > 0
Answer: True the minimum value for resolving number is greater than 0


[1 < 2 < 3, 3 < 2 < 1]
Answer: [True,true] True is 1,false is 0


24.2 = = [[[2]]]
Answer: True parsing: Both sides are converted to strings


25.
3.toString ()
3..toString ()
3...toString ()
Answer: Error, "3", error


26.
(function () {
var x = y = 1;
})();
Console.log (y);
Console.log (x);

A: 1,error y is the global one to note


27.
var a =/123/,
b =/123/;
A = = B
A = = = B
Answer: False,false parsing: Matching objects are not equal

27 JS Questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.