We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
let a = 1 let b = a++ console.log(`a 为 ${a},`, `b 为 ${b}`) // a 为 2, b 为 1
let a = 1 let b = a-- console.log(`a 为 ${a},`, `b 为 ${b}`) // a 为 0, b 为 1
let a = 1 let b = ++a console.log(`a 为 ${a},`, `b 为 ${b}`) // a 为 2, b 为 2
let a = 1 let b = --a console.log(`a 为 ${a},`, `b 为 ${b}`) // a 为 0, b 为 0
前缀操作符和后缀操作符很容易令人困惑,当然,以前靠记忆也能记住,现在直面规范更能理解。希望不要再被迷惑!
可以大致写个后缀模拟函数,不标准:
/* * @param {target} 目标数值 * @param {type} 只能是 '++' 或 '--' */ const postfix = (target, type) => { let old = Number(target) if (type === '++') { let newVal = old + 1 target = newVal } else if (type === '--') { let newVal = old - 1 target = newVal } else { throw '第二个参数只能传入 ++ 或 --' } return old }
前缀也类似。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
更新表达式
后缀++
后缀--
++前缀
--前缀
注意
前缀操作符和后缀操作符很容易令人困惑,当然,以前靠记忆也能记住,现在直面规范更能理解。希望不要再被迷惑!
可以大致写个后缀模拟函数,不标准:
前缀也类似。
The text was updated successfully, but these errors were encountered: