Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

函数实参与形参在严格模式下有什么不同 #17

Open
lovelmh13 opened this issue Mar 7, 2020 · 0 comments
Open

函数实参与形参在严格模式下有什么不同 #17

lovelmh13 opened this issue Mar 7, 2020 · 0 comments

Comments

@lovelmh13
Copy link
Owner

function fn (x, y) {
    console.log(x, y, arguments);
    arguments[0] = 100;
    y = 200;
    console.log(x, y, arguments);
}
fn(10, 20);

看打印结果可以知道,在非严格模式下,实参arguments和形参x, y是有映射关系的,改其中一个,另一个会跟着改

function fn (x, y) {
    "use strict"
    console.log(x, y, arguments);
    arguments[0] = 100;
    y = 200;
    console.log(x, y, arguments);
}
fn(10, 20);

而在严格模式下,,实参arguments和形参x, y是没有映射的,所以改了arguments[0]x并不会跟着改;改了yarguments[1]也不会跟着变

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant