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

lydiahallie/javascript-questions里我的错题 #31

Open
kangkai124 opened this issue Jul 16, 2019 · 5 comments
Open

lydiahallie/javascript-questions里我的错题 #31

kangkai124 opened this issue Jul 16, 2019 · 5 comments

Comments

@kangkai124
Copy link
Owner

from https://github.com/lydiahallie/javascript-questions

@kangkai124
Copy link
Owner Author

kangkai124 commented Jul 16, 2019

num的值是多少?
const num = parseInt("7*6", 10);
答案

答案:7

如果被解析参数的第一个字符无法被转化成数值类型,则返回 NaN。
如果被解析参数是数字+非数字字符,则只取前面的可以被转为数值的部分进行转换。

@kangkai124
Copy link
Owner Author

输出结果是什么
(() => {
  let x = (y = 10);
})();

console.log(typeof x);
console.log(typeof y);
答案

答案:"undefined", "number"

let x = y = 10 实际上是以下的缩写:

y = 10;
let x = y;

当对 y 赋值时,实际上是赋值到了 window.y,所以 window.y 的值为 10,typeof y'number'
但是使用 letx 声明时,由于块作用域的影响,在 IIFE 函数外面是无法访问到 x 的,所以 typeof x'undefined'

@kangkai124 kangkai124 changed the title lydiahallie/javascript-questions里的错题 lydiahallie/javascript-questions里我的错题 Jul 16, 2019
@kangkai124
Copy link
Owner Author

输出结果是什么
// counter.js
let counter = 10;
export default counter;
// index.js
import myCounter from "./counter";

myCounter += 1;

console.log(myCounter);
答案

答案:Error

一个被引入的模块是只读的,不能去修改引入的模块。

@kangkai124
Copy link
Owner Author

kangkai124 commented Jul 16, 2019

delete 操作符返回一个布尔值,删除成功返回 true,反之返回 false

但是,使用 varconstlet 关键字定义的变量不能使用 delete 删除。

@kangkai124
Copy link
Owner Author

输出是什么
let num = 10;

const increaseNumber = () => num++;
const increasePassedNumber = number => number++;

const num1 = increaseNumber();
const num2 = increasePassedNumber(num1);

console.log(num1);
console.log(num2);
答案

答案:10, 10

++ 操作符会先返回值,然后再累加。

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