0

I was just wondering how to declare a variable called variable in JavaScript.
Or a variable called function.
Of course, its not necessary
Is it possible?
Just wondering.
Like this?

var var = "some string"

(you probably can't with javascript but any other language where it's possible?)

MThead
  • 87
  • 1
  • 2
  • 7
  • You can't, reserved words can't be used as a variable name in JS. You can use reserved words as property names in an object, though in this case they must be wrapped in quotes, and refererred with bracket notation. – Teemu Feb 20 '15 at 20:59
  • you can add it to objects, so var obj = {}; obj.var = 'something' will work – Abraham Adam Feb 20 '15 at 21:01
  • I'm voting to close this question as off-topic because it has no value. Even the OP states this. – Steve Wellens Feb 20 '15 at 21:29

3 Answers3

0

No. Refer to a list of reserved words - it's not only function and var.

As for your second question in an edit: for example, there's special syntax in C# to declare variables with reserved names (What does placing a @ in front of a C# variable name do?).

Community
  • 1
  • 1
NikitaBaksalyar
  • 2,414
  • 1
  • 24
  • 27
0

As Nikita said, there are a bunch of reserved words you can't use like var and function. What (I think) you can do is put capitals like 'vAr' or 'functioN' but that's about as close as you can get to the actual word.

Chickenator
  • 109
  • 1
  • 6
0

in MySQL you can use reserved word if you quote them like:

C

CREATE TABLE interval (begin INT, end INT); //this can't

CREATE TABLE `interval` (begin INT, end INT); //this can
Luis Sk
  • 17
  • 6