Skip to content Skip to sidebar Skip to footer

Javascript : Syntax Error On Token "delete", Stringliteral?

var TestFunction = function () { return { delete: function() { // line 1 // do something } }; } Getting below error

Solution 1:

Yes, delete is a reserved keyword, used to remove a property in an object, so that it is not iterable anymore. Thus, given:

var a = { b: 5 };
delete a.b;
console.log(a);
// logs {}

It can be also used to remove "global variables" that are actually properties of the global object too, that is:

delete a;
// is in browsers equal todeletewindow.a;

Notice that you can use delete as a property name too, however you need to always quote it:

var obj = {
    'delete': function() { // line 1// do something
    }
};
obj['delete']();

Post a Comment for "Javascript : Syntax Error On Token "delete", Stringliteral?"