Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

What is the result of the following statement? Why? And how to have the result expected?

for(var i =0; i <; i++) {

  setTimeout(function() {

    console.log(i);  

  },);

}

user-image
Question added by Jonathan de Flaugergues , software engineer , Abbeal
Date Posted: 2017/01/24
Amir Khan
by Amir Khan , LAMP/PHP Web Programmer , GTA Web Developers

Assuming the language is Javascript, knowing setTimeout and console.log there are2 obvious syntax errors:

1. Line #1: Missing the value after i <

2. Line #4:  Comma after curly bracket close

 

To run the script let's say i < then:

 

<script>

 

for(var i =0; i <; i++) {

 

  setTimeout(function() {

 

    console.log(i);  

 

  });

 

}

 

</script>

 

Thanks and Good Luck!

 

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.