JS code execution, will there be half of the Function A () code execution, and then to execute the Function B () code?

as mentioned, we have the following business requirements

var x=[];

function A(){
X
}

function B(){
X
}

I"m worried now, because both function An and B are dealing with X. if there is a run-time crossover, it will cause some code logic problems.
in a database, it is generally in the form of a locked table to prevent X from being modified by both operations at the same time.
but in JS, is there any way to avoid this?
or, in other words, the way the JS code runs, this will not happen at all. It is certain that the complete code block will run before the next code block will be run.

Thank you

Mar.10,2021

No, single thread will not appear


without the concept of and , the code will be executed, but not necessarily the result (I think that's what you're asking). For example, if there is an asynchronous method in function , it appears that An executes to a certain part of execution B and then executes A.

var x = [];

function A() {
    setTimeout(() => {
        x[0] = 'A'
        setTimeout(() => { console.log('A', x) }, 0)
    }, 0)
}

function B() {
    setTimeout(() => {
        x[0] = 'B'
    }, 0)
}

A();
B();

the solution is the problem of asynchronous flow control. Search for a lot of it.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3a8eb-41264.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3a8eb-41264.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?