Take a look at this short code snippet (jsfiddle):
<div ng-app="App" ng-init="foo={a: 20}; delete foo['a']">
</div>
This causes a syntax error in both Firefox and Chrome browsers. But why?
The syntax error states, "Token 'foo' is an unexpected token at column 21 of the expression [foo={a: 20}; delete foo['a']] starting at [foo['a']]."
Interestingly, using delete foo['a']
or delete foo.a
results in functionality in pure JavaScript but not when introduced within the ng-init
directive.