- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果变量驻留在不执行的 if 语句中,是否会初始化/存储在内存中,如下所示:
function blah(){
if(something === true){
var blahOne = 1;
var blahTwo = 2;
var blahThree = 3;
} else {
console.log('The above if statement usually won\'t execute');
}
}
我的假设是否定的,但至少可以说 Javascript 是一种古怪的语言。预先感谢您的帮助!
最佳答案
所有 var
声明都被移动到函数的顶部并初始化为未定义。这就是所谓的变量提升。 JavaScript 没有 block 范围,只有函数和全局范围。
你的代码等同于下面的
function blah(){
var blahOne, blahTwo, blahTree;
if(something === true){
blahOne = 1;
blahTwo = 2;
blahThree = 3;
} else {
// blahOne, blahTwo, blahThree are set to undefined
console.log('The above if statement usually won\'t execute');
// But since they have been declared, there's no error in reading them
console.log(blahOne, blahTwo, blahThree);
}
}
关于Javascript 内存节省 - if 语句 var 声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22796601/
我试图找出在将数据传输到设备之前将数据复制到固定内存是否有意义,因为我对输入数据的分配没有影响(它是一个库)。 std::vector idata(WORK_SIZE); int *idata_ali
model.save() 让我很困惑。 示例。我将我的 mongoose.model(mongoose.schema) 移动到单独的 model.js 文件中。当我使用这种方法创建模型时,以下问题困扰
我正在用 Java Swing 制作模拟时钟。要计算我需要的时钟指针角度: 我可以通过 System.currentTimeMillis() 获得的以毫秒为单位的 UTC 时间 时区偏移 TimeZo
编辑 我的应用程序中有声音,该声音在应用程序启动时开始播放。此外,我还有两种播放和停止声音的方法: -(void)playBgMusic { NSString *path = [[NSBundle m
所以我的应用有 1 个 Activity 和 4 个 fragment ,其中一个有 Chronometer 来显示经过了多少时间。 它工作正常,但我有一个问题,每次我移动到另一个 fragment
我是 FireDAC 新手,遇到问题。我想在Delphi XE7中使用FireDAC读写SQLite数据库。我尝试的大部分方法都有效,但我在将 TTime 保存到 SQLite DB 时遇到问题。 这
这是我使用基本 Node.js 服务器创建的示例站点。我能够成功发布、创建给定架构的用户,然后“保存”到数据库;但是,保存不会返回用户对象,并且在我的实际数据库中找不到。连接也返回成功。 main.j
我有一台配备 2 Gb Nvidia GPU 的 Mac Book Pro。我正在尝试利用我所有的 GPU 内存进行计算(python 代码)。如果我绕过 GUI 界面并仅通过命令行访问我的机器,我可
我希望使用 Powerpoint 创建一种测验,我想保存用户提供的输入。 例如:如果我问这个问题:你最喜欢什么颜色?当他们回答问题并单击下一步按钮时,我想保存文本框的值并将其附加到输出文件中。 我已经
我是一名优秀的程序员,十分优秀!