Some interesting phenomena in JS

Source: Internet
Author: User

1,js about function promotion (in ES5)

function f () {Console.log (' I am outside! ' )}    (function() {        if(false) {//             The function f () {Console.log ("I am inside!") that declares a function in the  if, loop code block is certainly not allowed in strict mode.             )}        }}        (f ();    }) ();     // The result is I am inside!      Because there is a variable function promotion in ES5,  repeated declarations, followed by overwriting the front, so the final function is functions f () {Console.log ("I am inside!")}

Using a let declaration in ES6 produces a block-level scope without immediately executing an anonymous function.

2.

alert (a) a (); var a=3; function A () {    alert (ten)}   alert (a) a=6; a ();   ------------Split Line------------------alert (a) a (); var a=3; var a=function() {    alert (ten)}   alert (a) a=6; a (); Link: https://juejin.im/post/5a0c170c6fb9a0451c39eff2

Some interesting phenomena in JS

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.