If I want to use the following in JS, Is some option available to do it?
var break = "";
In C# we have the option to use it using @, is similar option available in JS
public int @public;
If I want to use the following in JS, Is some option available to do it?
var break = "";
In C# we have the option to use it using @, is similar option available in JS
public int @public;
Share
Improve this question
asked Jul 28, 2016 at 20:15
VijaiVijai
2,5273 gold badges28 silver badges34 bronze badges
2
- 4 You don't, for obvious reasons. And no, there's no way to use reserved keywords as variable names, and why would you, you have an infinite number of other choices than the few reserved words. – adeneo Commented Jul 28, 2016 at 20:16
-
1
Just use another character in front of it, like a
$
or_
– castletheperson Commented Jul 28, 2016 at 20:20
2 Answers
Reset to default 8Well, if you insist, you can
var $break = 1;
which is the same as C# in terms of characters ;)
Seriously, you cannot use reserved keywords as variables, but they are allowed as property names:
myObj = {}
myObj.break = 'whatever';
Also, do note that the repertoire of the reserved words varies depending on the strictness. For example,
var interface = 1;
is valid in the non-strict mode, but breaks once you add use strict
to your script.
You can't use Javascript keywords as a variable name.