- Joined
- Jan 29, 2023
- Messages
- 1
- Reaction score
- 0
I'm developing a javascript program that will take info from a user prompt and use that info in an if statement.
the output from the script is stored in a variable NEW_LINE which will be used in an if statement.
in one example, NEW_LINE generates this value: (input_line.indexOf("bob") != -1) || (input_line.indexOf("robert") != -1)
The following statement always evaluates as true even when it is false.
if (new_line)
{alert("new_line = true");}
else {alert("new_line = false");}
However, when I copy the contents of NEW_LINE into the if statement as shown below it always works correctly.
if ((input_line.indexOf("bob") != -1) || (input_line.indexOf("robert") != -1))
{alert("new_line = true");}
else {alert("new_line = false");}
Anyone have any ideas? Why do they evaluate differently as they are evaluating the same content?
It's driving this 81 year old crazy.
the output from the script is stored in a variable NEW_LINE which will be used in an if statement.
in one example, NEW_LINE generates this value: (input_line.indexOf("bob") != -1) || (input_line.indexOf("robert") != -1)
The following statement always evaluates as true even when it is false.
if (new_line)
{alert("new_line = true");}
else {alert("new_line = false");}
However, when I copy the contents of NEW_LINE into the if statement as shown below it always works correctly.
if ((input_line.indexOf("bob") != -1) || (input_line.indexOf("robert") != -1))
{alert("new_line = true");}
else {alert("new_line = false");}
Anyone have any ideas? Why do they evaluate differently as they are evaluating the same content?
It's driving this 81 year old crazy.