Jump to content

JS anomaly.


Omirion

Recommended Posts

function test(myTrig,t){
var num = arguments.length
if (num == 0){
	alert("preset stage");
	setTimeout(function(){test(1,1)},2);
} if (myTrig == 1){
	alert("starting first recursion");
	if (t==1.5 || t>1.5) {
		alert("exiting"); 
		return ;
	}
	alert(myTrig);
	alert(t);
	t += 0.1;
	setTimeout(function(){test(1,t)},2);
} if (myTrig == 2){
	alert(myTrig);
}
}

 

When this function is run clean like so

test();

 

It passes trough a preset stage and then is passed on to the first recursive part of the code.

 if (myTrig == 1){
	alert("starting first recursion");
	if (t==1.5 || t>1.5) {
		alert("exiting"); 
		return ;
	}
	alert(myTrig);
	alert(t);
	t += 0.1;
	setTimeout(function(){test(1,t)},2);

 

Each time var t is incremented by 0.1.

But not exactly, a 0.000000001 value is also added.

 

 

Any JS magician care to explain?

Link to comment
https://forums.phpfreaks.com/topic/194985-js-anomaly/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.