How concurrent variable access is controlled in javascript

I am working on a chrome extension that uses asynchronous functions, and I have a global string variable that is set by the function:

my_global_variable + = a_string

I would know if there is a risk that if I read my_global_variable in another function at the same time, I only have a_string part.

In other words, is concatenation (a more general instruction) an atomic operation?

+4
source share
2 answers

Javascript is threaded in the browser (unless HTML5 Web Workers is used), so there is no competition for access to the variable. In Chrome, there was streaming through the Gears plugin, but this was discontinued in favor of HTML5 . Web workers .

+3
source

Yes. Concatenation is an atomic operation in Javascript.

+2
source

Source: https://habr.com/ru/post/1391731/


All Articles