search
HomeWeb Front-endJS TutorialAnother javascript quiz (code collection)_javascript skills

You can test your level of knowledge in this area.
At the end of the question is my analysis of the topic with reference to the original blogger’s articles and comments, and everyone is competing to get the answer.
The quiz:
1:
1 && 3
2:
1 && "foo" || 0
3:
1 || "foo" && 0
4:
(1,2,3)
5:
x = {shift:[].shift};
x.shift(); 3: x.length;
6:
{foo:1}[0]
7:
[true, false][ true, false]

8:
'52'.split(' ')[0]
9:
a: b: c: d: e: f: g: 1, 2, 3, 4, 5;
10:
{a: 1, b: 2}[["b"]]

1
"b" 45
12:
{a:{b:2}}
13:
(function(){}())
14:
[1,2,3,4,5][0..toString.length]

15:
({} 'b' > {} 'a')

16:
Number.prototype.x = function(){ return this === 123; };
(123).x() ;
17:
Array(2).join()
18:
vars: var vars = vars;
19:
{ foo = 123 }
20:
x = 1; (function(){return x; var x = 2;}())

2
delete [].length;

22:
RegExp.prototype.toString = function() {return this.source};
/3/-/2/;
23:
{break;4;}
24:
'foo' == new function(){ return String('foo'); };

25:
'foo'.split('') []

Analysis:

1: #1. //3: 1 is true, and the && operation continues to execute the expression on the right, and the result is 3
2: #2. //"foo": logical operator, Same as above, when the operation reaches "foo", the expression has been successful and the expression on the right side of || is no longer executed
3: #3. //1: 1 is converted to bool and is true, and is returned directly, no Then execute
4: #4. //3: Always return the last value
5: #5. //0: When x executes the shift() method, x will have the length attribute. And the returned value is 0
6: #6. //[0] : Two expressions, return the result of the last expression
7: #7. //true : Operate on bool, the result is 1 or 0 is [true,false][1,0], and this formula always takes the last one, [true,false][0]
8: #8. //6: .Operator priority Level greater than operator, '52'.split('')->['5','2']; take [0] to get 5; get 6
9: #9. //5: Ignore the front All :x gets: a:1,2,3,4,5 Result: 5
10: #10. //SyntaxError. Maybe you will be surprised. Isn’t this data in json format? Why does it report an error? I was very surprised at first. In fact, this is not a JavaScript object, but a statement execution of a block-level structure, because there is no assignment statement. When executed as an ordinary statement, {a:1;b:2} is correct. Or a={a:1,b:2}
11: #11. //"b45": Addition of string and number always returns string
12: #12. //2: It's just two statement blocks. It's actually the same situation as question 9 a:b:2, return 2
13: #13. //undefined: The anonymous empty function executes itself, because the return statement is not displayed , automatically returns undefined.
14: #14. //2: This is very interesting. Let’s talk about it in two parts, let’s talk about 0..toString first. If you add "." after an integer, then JavaScript will think it is the point of the floating point number, not the point of the attribute call. If you add a dot after the floating point number, then JavaScript will think it is the point of the attribute call, because JavaScript cannot distinguish this time. What does the user want to do? So 0.. becomes a calling attribute. (This is my guess) At this time, 0. will be converted into an object and its toString function will be called. If you directly use 0.toString, a syntax error will occur. You can test 1.1.toString;.0.toString, etc., they are all callable. Let’s talk about the result of 0..toString.length: 1. Why is it 1? The result returned by calling the length attribute of the function is the number of formal parameters of the function. The default number of formal parameters of the number.toString function in JavaScript is 1. Therefore, the result of [1,2,3,4,5][1] is 2.
15: #15. //true: {} "b" object and string are added -> "[object Object]b", and then logical comparison is performed, "b" > "a". Please do not test {} "b" directly. You will

get NaN. Why? If so, execute the {} statement block first, and then execute "b". The result will naturally be NaN.

16: #16. //false Strict comparison, object on the left, number on the right, type mismatch.
17: #17. //'','': The array is converted into a string after using join, but it is an empty array, so the above result is obtained.
18: #18. //undefined: They are all salted fish, no matter how they turn around, they are still salted fish. They are all undefined, and of course they are still undefined in the end.
19: #19. //123: Block statement execution. She has a little bit to do with her partner, Shenma.
20: #20. //undefined: It is said that every time JavaScript introduces a block scope, it will scan the "var" in the block scope and set the variable value with var life to undefined, regardless of whether it has been done before. Class declaration, including function body.
21: #21. //false: Delete the hair. Can this be deleted? [delete only returns false when a property can not be deleted.]

Reference: http://perfectionkills.com/understanding-delete/ The article makes it very clear that some properties of built-in functions cannot be deleted. , similar to arguments,

length, local variables of functions (function(){ var a = 1; return delete a })(), etc.

22: #22. //1: First modify the toString function on the prototype chain of the regular expression to return the text form of the current regular expression instance object. Then the strings are subtracted. At this time, they will be automatically converted into numbers for calculation.23: #23. // SyntaxError: break statements can only be placed in loops and switch branch statements 24: #24. //false: Borrowing Damian Wielgosik’s very classic explanation (new function(){ return String('foo') ; }).toString() != 'foo'
25: #25. //"f,o,o": After converting the string into an array, add it to the array and then convert it into a string. You can find two Try adding arrays, borrowing Damian Wielgosik’s explanation

Just consider e.g. [1, 2] [3, 4] and see how arrays are casted to string.

Statement
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
Python vs. JavaScript: A Comparative Analysis for DevelopersPython vs. JavaScript: A Comparative Analysis for DevelopersMay 09, 2025 am 12:22 AM

The main difference between Python and JavaScript is the type system and application scenarios. 1. Python uses dynamic types, suitable for scientific computing and data analysis. 2. JavaScript adopts weak types and is widely used in front-end and full-stack development. The two have their own advantages in asynchronous programming and performance optimization, and should be decided according to project requirements when choosing.

Python vs. JavaScript: Choosing the Right Tool for the JobPython vs. JavaScript: Choosing the Right Tool for the JobMay 08, 2025 am 12:10 AM

Whether to choose Python or JavaScript depends on the project type: 1) Choose Python for data science and automation tasks; 2) Choose JavaScript for front-end and full-stack development. Python is favored for its powerful library in data processing and automation, while JavaScript is indispensable for its advantages in web interaction and full-stack development.

Python and JavaScript: Understanding the Strengths of EachPython and JavaScript: Understanding the Strengths of EachMay 06, 2025 am 12:15 AM

Python and JavaScript each have their own advantages, and the choice depends on project needs and personal preferences. 1. Python is easy to learn, with concise syntax, suitable for data science and back-end development, but has a slow execution speed. 2. JavaScript is everywhere in front-end development and has strong asynchronous programming capabilities. Node.js makes it suitable for full-stack development, but the syntax may be complex and error-prone.

JavaScript's Core: Is It Built on C or C  ?JavaScript's Core: Is It Built on C or C ?May 05, 2025 am 12:07 AM

JavaScriptisnotbuiltonCorC ;it'saninterpretedlanguagethatrunsonenginesoftenwritteninC .1)JavaScriptwasdesignedasalightweight,interpretedlanguageforwebbrowsers.2)EnginesevolvedfromsimpleinterpreterstoJITcompilers,typicallyinC ,improvingperformance.

JavaScript Applications: From Front-End to Back-EndJavaScript Applications: From Front-End to Back-EndMay 04, 2025 am 12:12 AM

JavaScript can be used for front-end and back-end development. The front-end enhances the user experience through DOM operations, and the back-end handles server tasks through Node.js. 1. Front-end example: Change the content of the web page text. 2. Backend example: Create a Node.js server.

Python vs. JavaScript: Which Language Should You Learn?Python vs. JavaScript: Which Language Should You Learn?May 03, 2025 am 12:10 AM

Choosing Python or JavaScript should be based on career development, learning curve and ecosystem: 1) Career development: Python is suitable for data science and back-end development, while JavaScript is suitable for front-end and full-stack development. 2) Learning curve: Python syntax is concise and suitable for beginners; JavaScript syntax is flexible. 3) Ecosystem: Python has rich scientific computing libraries, and JavaScript has a powerful front-end framework.

JavaScript Frameworks: Powering Modern Web DevelopmentJavaScript Frameworks: Powering Modern Web DevelopmentMay 02, 2025 am 12:04 AM

The power of the JavaScript framework lies in simplifying development, improving user experience and application performance. When choosing a framework, consider: 1. Project size and complexity, 2. Team experience, 3. Ecosystem and community support.

The Relationship Between JavaScript, C  , and BrowsersThe Relationship Between JavaScript, C , and BrowsersMay 01, 2025 am 12:06 AM

Introduction I know you may find it strange, what exactly does JavaScript, C and browser have to do? They seem to be unrelated, but in fact, they play a very important role in modern web development. Today we will discuss the close connection between these three. Through this article, you will learn how JavaScript runs in the browser, the role of C in the browser engine, and how they work together to drive rendering and interaction of web pages. We all know the relationship between JavaScript and browser. JavaScript is the core language of front-end development. It runs directly in the browser, making web pages vivid and interesting. Have you ever wondered why JavaScr

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.