How to prevent a javascript function from evaluating an argument assigned to a string variable?

StackOverflow https://stackoverflow.com/questions/19717244

Pergunta

Edited for clarification:

function Num(str) { 
  return str;
}

which returns when the input is 2^15

13

I want to know how I can keep it from evaluating str and just return 2^15 instead of returning 13.

Foi útil?

Solução

var string = "2^15"; // wrap in double quotes to treat it as a string

As a sidenote, avoid calling your variables 'string', since it is a reserved keyword in a lot of languages and reduces readability.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top