Reputation: 327
Here's my code
var isNew = true
function limb(a,b)
{
if (isNew=true)
{
post(a,b);
isNew = false;
post ("first");
}
else
{
post(a,b);
post ("not first");
}
}
The problem I'm having is that else
condition is never triggered. I'm assuming value of isNew
is never updated, but I have no idea why.
Upvotes: 0
Views: 154
Reputation: 129756
In some languages =
is used both to assign values and to compare them. JavaScript uses different operators for each of these.
x = 10
always means "set x
to 10
, and give me the value of x
".
x == 10
always means "tell me if x
is equal to 10
".
So your condition could have been if(isNew == true)
and it would have worked. You can also just put if(isNew)
.
Upvotes: 2