Click to See Complete Forum and Search --> : Please explain this line of code...


mini_dumbo
12-30-2002, 06:27 PM
hi all:

we encountered this block of javascript code but we don't understand a line within this block.... can somebody explain to us what it means??

====from this block of code=========

while (ls.length>12){
ab=eval(ls.substring(0,2))-89;
----->this line---ab1=(ab1==""?""+ab:ab1); <---------
oab1=ab1;
ls=ls.substring(2,ls.length);
for (var i=0;i<ab;i++){
nr=eval(ls.substring(0,2))-a;
ls=ls.substring(2,ls.length);
nls+=al.charAt(nr);
}


================================


any help will be appreciated!!


Bo & Vic

khalidali63
12-30-2002, 06:37 PM
looks wrong code to me.

khalidali63
12-30-2002, 06:39 PM
I have a feeling it should be like this..but its just a thought.

ab1 = (ab1=="?")? ab:ab1;

Craiga
12-30-2002, 10:29 PM
ab1=(ab1==""?""+ab:ab1);

Better written:

ab1 = (ab1=="" ? ""+ab : ab1);

Here is what it means in if-statements:

if(ab1 == ""){
ab1 = ""+ab;
}else{
ab1 = ab1;
}

Basically its checking to see if ab1 = "" or nothing, and if it does, assign ab1 to ""+ab, the "" would just make it a string. If it doesn't equal "" then leave it as itself (reasign it to itself)

Charles
12-31-2002, 04:53 AM
And eval(ls.substring(0,2)) means exactly the same thing as ls.substring(0,2). I have only ever found one example of the eval function being needed.

Craiga
12-31-2002, 05:36 PM
I can think of tons of places to use the eval()!

Charles
12-31-2002, 06:24 PM
Originally posted by Craiga
I can think of tons of places to use the eval()! There are few places where you cannot use it because in all but a few rare instances it does absolutely nothing. See http://developer.netscape.com/docs/manuals/js/client/jsref/toplev.htm#1063795 for those instances and a lot of examples of it doing nothing.