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
  • 24,798
  • 16
  • 106
  • 125

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
  • 66,765
  • 14
  • 157
  • 225
0

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

Mathias Schwarz
  • 6,939
  • 21
  • 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,592
  • 4
  • 37
  • 47
-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,018
  • 3
  • 18
  • 21