Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Can someone please breakdown this script for me and tell me how the outcome is 30105? Thanks alot guys

function one(numOneIn) {

two(numOneIn * 3); //1x3

document.write (numOneIn); //3

}

function two(aNumberIn) { 

document.write (aNumberIn); //1

}

function three(numIn) {

one(numIn * 2); 

document.write (numIn);

}

three(5);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.2k views
Welcome To Ask or Share your Answers For Others

1 Answer

three(5)

calls three, passing the number 5, then:

one(numIn * 2);

calls one, passing 5 x 2 => 10, then:

two(numOneIn * 3)

calls two, passing 10 x 3 => 30, then

two writes "30" as a string to the document.

Control returns to one, which writes the value passed to it (10) as a string.

Control returns to three, which writes the value passed to it (5) as a string.

So the final string is "30105".


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...