0

So I am passing a string into a javascript function. for example:

function dothis(x,y,z){
    something
}

dothis(year,month,contract); // contract = "A10-009_xyz"

I know this has something to do with the way javascript deals with 08 and 09, but I am unsure of the best way to deal with it in my case.

the error I'm getting is

09 is not a legal ECMA-262 octal constant
dothis(2012, 01, A10-009_xyz);

I saw some people suggesting using number(string) or parceInt("09","10") but I'm unsure of how to impliment with this as the string will be changing a lot. Am I supposed to check the string before placing into the function and look for 08,09 and replace with the parceInt()?

Thanks for any help, suggestions etc appriciated.

Leandro Bardelli
  • 10,561
  • 15
  • 79
  • 116
3dsanity
  • 31
  • 1
  • 4
  • Um, it is complaining when you are calling the method? That does not make sense. – epascarello Jun 20 '13 at 16:00
  • Yes, I could be confused as I have never ran into this problem before. Sorry for the confusion – 3dsanity Jun 20 '13 at 16:03
  • If you're quoting the string, it shouldn't cause a problem when calling the function. The problem must be with what the function does with `z`, you need to show that. – Barmar Jun 20 '13 at 16:05
  • What you typed and what the error message shows seems like you are missing quotes. – epascarello Jun 20 '13 at 16:06
  • In Javascript, if a number begins with `0`, it's treated as octal. But it shouldn't be interpreted as a number if you quote it. And you shouldn't call `parseInt()` if it's not supposed to be a number. – Barmar Jun 20 '13 at 16:10
  • I updated my questions, I'm actually passing a variable into the function. I apologize, I don't know if this effects it but I'm using coldfusion to pass in variable to the function – 3dsanity Jun 20 '13 at 16:11
  • Yea i didn't think either the parseInt or number functions would be of any help in my case. – 3dsanity Jun 20 '13 at 16:12
  • It shouldn't matter whether you pass it as a variable or literal, as long as you quoted it when you assigned the variable. – Barmar Jun 20 '13 at 16:13
  • Are you using `eval()`? – Barmar Jun 20 '13 at 16:15
  • Ok, I guess I was assuming that js would interpret it as a string since the variable it-self was a string. Thanks! – 3dsanity Jun 20 '13 at 16:16

0 Answers0