Function Parameters Question

MonetishMonetish Texas
edited January 2016 in JavaScript

I'll start out straight forward in case anyone has the answer off the bat.

What is this: '+val1+'

I saw a video on this with it in a parameter like the following longer one below calling a setTimeout:


..............(code to return the val1 and val2 into html, then this below was to continue to repeat the function with the new val1 value).....


    var timer = setTimeout('countDown('+val1+','+val2+')',1000);

It was used to create a countdown clock and it worked for me, but I don't completely understand how in reference to that one part. I get the code as a whole but not that part...

What are the quotes with plus signs around the variables in the parameters for? Why is it '+val1+' and what are the plus signs on each side for? Is this the only way the variables can be called from here or the only way to return their new values as the function repeats or something else... I'm confused about this part completely.


  • Plus sign acts as string concatenation.

    var a = 'world';
    var b = 'Hello ' + a + '!'; // Hello world!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion