I am a javascript learner Hear is my javascript
I have a javascript function named get();
which i call it onload.
function get() {
for (var i = 1; i <= 5; i++) {
setTimeout(function() {
console.log('Value of i : ' + i);
}, 100);
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
</head>
<body onload="get();">
</body>
</html>
The expected output is
Value of i : 1
Value of i : 2
Value of i : 3
Value of i : 4
Value of i : 5
where as i am getting
Value of i : 6
Not able to figure out what is exactly is wrong .