A wrong (and now fixed) code in our app triggered this error :
TypeError: Cannot create property 'FOO' on string 'BAR'
But Javascript pletely allows setting free properties on a string variable. I just tried it in Chrome console :
'BAR'.FOO = 'hello'
'BAR'['FOO'] = 'hello'
And it works perfectly.
So in which context do the JS interpreter trigger this error ?
The original code is written in Typescript, then transpiled with Babel. This is a runtime error. I assume this is not related to typescript since other people report a similar runtime error, ex. here and here
A wrong (and now fixed) code in our app triggered this error :
TypeError: Cannot create property 'FOO' on string 'BAR'
But Javascript pletely allows setting free properties on a string variable. I just tried it in Chrome console :
'BAR'.FOO = 'hello'
'BAR'['FOO'] = 'hello'
And it works perfectly.
So in which context do the JS interpreter trigger this error ?
The original code is written in Typescript, then transpiled with Babel. This is a runtime error. I assume this is not related to typescript since other people report a similar runtime error, ex. here and here
Share Improve this question edited Oct 6, 2017 at 12:07 user229044♦ 239k41 gold badges344 silver badges346 bronze badges asked May 23, 2016 at 14:25 OffirmoOffirmo 19.9k13 gold badges81 silver badges99 bronze badges 02 Answers
Reset to default 13So in which context do the JS interpreter trigger this error ?
Strict mode.
'use strict';
'BAR'.FOO = 'test';
'use strict';
var string = { name: 'bar' };
string.foo = 'hello';
console.log(string.foo + ' ' + string.name);