简体   繁体   English

鉴于代码行是同步的,节点 js 中的行的执行顺序是什么

[英]Given the lines of code are synchronous, what would be the order of execution of the lines in node js

For example,例如,

var doSomething = function() {`
    var a = 1, b = 2, c = 3;
    var d = a;
    b = b - 3;
    d = b;
    console.log(a,b,c,d);
}

doSomething();

Is there any possible situation beginning from the dawn of the universe until the end, that the output of the code when executed in node js - built on JavaScript's V8 engine would be anything other than 1 -1 3 -1.从宇宙的黎明开始到结束,是否有任何可能的情况,在节点 js 中执行时代码的输出 - 建立在 JavaScript 的 V8 引擎上,不是 1 -1 3 -1。

Is there any combination of synchronous lines of code that do no execute in the order they are written.?是否有不按编写顺序执行的同步代码行的任何组合。?

Any puns are not welcome and any help is appreciated.不欢迎任何双关语,任何帮助表示赞赏。

Additional question:补充问题:

var index = commonFunc.getObjectIndexFromArray(option[0].fields.custom_field, tableAccess.checkDomainInTable.selected_template); 
if (option[0].fields.custom_field && option[0].fields.custom_field.length > 0 && index >= 0) {
    userOptions = option[0]['fields']['custom_field'][index][tableAccess.checkDomainInTable.selected_template]; 
} 
if(tableAccess.checkDomainInTable.delivery_template) { 
    index = commonFunc.getObjectIndexFromArray(option[0].fields.custom_field, tableAccess.checkDomainInTable.delivery_template); 
    if (option[0].fields.custom_field && option[0].fields.custom_field.length > 0 && index >= 0) {
        deliveryOptions = option[0]['fields']['custom_field'][index][tableAccess.checkDomainInTable.delivery_template]; 
    } 
} 

In the above code, after assuming that the common function gets the index of a json object from an array of json object using simple for loop, can there be any situation in which the second occurence of the assignment of the variable index be executed first and the first occurence after that & causes an ambiguity in the values of userOptions and deliveryOptions ?上面代码中,假设common函数通过简单的for循环从json对象数组中获取json对象的索引后,会不会有第二次出现的变量索引的赋值先执行后的情况?之后的第一次出现 & 导致 userOptions 和 deliveryOptions 的值含糊不清?

如果这是整个代码,并假设 V8 实现或底层硬件中没有错误 - 不,此代码将始终以相同的顺序执行并具有相同的结果(即您提供的结果)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM