1
01. (function(){
02. function b(e){if(!d[e]){var f=d[e]={exports:{}};c[e].call(f.exports,a,f,b)}
03. return d[e].exports
04. }
05. var a=this,c=b.modules=[],d=b.cache=[];
06. c[0]=function(a,b,c)
07. {
08. var d=this;
09. 1;
10. var e=c(1),g=c(3).Builder,h=c(11);var i=c(10);
11. var j=c(15).Circle;var k = c(17).Friend; 
12. l=c(18).SearchFriends;c(19);

This is an fb app code that i have copied from fb friend circles, i am working in a different manner but was going through this script,where

FUNCTION c[0] has a variable 1 in it ...


How can bare numbers be used as variable names in javascript .. ?

Mathias Bynens
  • 144,855
  • 52
  • 216
  • 248
Nina
  • 21
  • 1
  • 3
  • possible duplicate of [Valid Characters for JavaScript Variable Names](http://stackoverflow.com/questions/1661197/valid-characters-for-javascript-variable-names) – Dan D. Jul 03 '11 at 22:56
  • `c()` is a function on lines 10-12, passed in on line 6 (third parameter), the number is just a parameter to that function. – Orbling Jul 03 '11 at 22:58
  • @Dan D. dude that is an expression or a type it is not a duplicate of any other topic.. such a question has never been asked ..!! – Nina Jul 03 '11 at 23:23

3 Answers3

3

That's not a variable, that's an expression.

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
  • please elaborate.. how this expression evaluates ..?does that expression mean function c[0] returns true always ..? – Nina Jul 03 '11 at 23:15
  • `1` *is* an expression. so is `1+3`. a couple of languages allow using expressions without actually using them (without assigning them to something or using them as a call parameter to a function, etc...). It's a no-operation – Karoly Horvath Jul 04 '11 at 07:56
1

Javascript variable names must begin with a letter or underscore or $. They may contain numbers, but not start with a number.

The statement you asked about:

1;

is a no-op. It's an expression that evaluates to a value of one, but since it isn't assigned to anything, it doesn't do anything. It doesn't declare a variable. Chances are it's a typo of some kind in the source you started with.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • Variable names may also begin with `$`. – user113716 Jul 03 '11 at 23:03
  • {view:"DetailCard",id:"card",pos:"w:88px h:95px",visible:!1} the expression has also been used inside the json array, may be its a boolean but it does appear like an expression – Nina Jul 03 '11 at 23:10
  • @Nina. What is your question about that code? That is an object declaration that has attributes o.view, o.id, o.pos and o.visible. – jfriend00 Jul 03 '11 at 23:12
  • i posted {//json content goes here} because the strange expression or variable is possibly also used inside the json, may be i am wrong – Nina Jul 03 '11 at 23:17
0

They are not numbers, they are function calls.
For example, if you have

function c(num){
  if(num == 10) return "Edgar";
}

when you do:

c(10)

You get "Edgar" (the function evaluation).
Hope this helps. Cheers

Edgar Villegas Alvarado
  • 18,204
  • 2
  • 42
  • 61