maybe you wanted
tanlat= Math.tan(lat)
not Math.atan(lat)
which is the inverse...
But then you have another problem: all the arguments to the trigonometric functions should be radians, not degrees. You will have to multiply degrees by Math.PI / 180
But then you have even more problems. The tan(23.44)
is not a quantity you need, you need the tan
of a product, to start with.
What I would do is simply take your formula as it is, adding only the degrees to radians conversion:
var deg2rad = Math.PI / 180;
var rad2deg = 180 / Math.PI;
var result = rad2deg / 15 * Math.acos(-Math.tan(lat*deg2rad) *
Math.tan(23.44*deg2rad * Math.sin(360*deg2rad * (d + 284) / 365)))