2

I am having some issues in my production code and I want to be able to send a flag to enable/disable JS logging, so I want to write my own logging function.

I want to use something like function log(){...}. When I looked up reserved words in JS I didn't see log listed, but I do see it listed in the w3schools docs as a math function.

Is it okay to use log() as a function name in production code for IE 7+, Chrome, and FF?

Justin
  • 26,443
  • 16
  • 111
  • 128

5 Answers5

3

Yes, it is absolutely fine. The maths log function is a function on the Math object, so will not collide with your implementation.

If you are confused by this sort of thing, look into JavaScript 'namespaces'

How do I declare a namespace in JavaScript?

Community
  • 1
  • 1
ColinE
  • 68,894
  • 15
  • 164
  • 232
0

Yes, it is ok. The math log function is available as Math.log, not log so you won't break anything...

Mathias Schwarz
  • 7,099
  • 23
  • 28
0

That should be fine. The mathematical log function is called via Math.log(x).

0

Yes it is ok. The math log function always needs to be called as Math.log(). So you're fine.

Sajjan Sarkar
  • 3,900
  • 5
  • 40
  • 51
-1

I would suggest using an existing object or namespace rather than making your log function global.

See http://www.yuiblog.com/blog/2006/06/01/global-domination/

Aaron Kurtzhals
  • 2,036
  • 3
  • 17
  • 21