My FeedDiscussionsHeadless CMS
New
Sign in
Log inSign up
Learn more about Hashnode Headless CMSHashnode Headless CMS
Collaborate seamlessly with Hashnode Headless CMS for Enterprise.
Upgrade ✨Learn more

Const KeyWord Confusion in Javascript

Default profile photo
Anonymous
·Jul 11, 2018
function fib(n){
  let result =[0,1];
  for(let i=2;i<=n-1;i++){
const a =result[i-1];
const b = result[i-2];
result.push(a+b);
  }

return result;
}
console.log(fib(4));

// In the above code snippets everything is working fine only confusion is regarding the thesis behind the const keyword ,as according to ES6 we cannot change the value of variable with const keyword ,but in the above code snippets there is a continuous changing of the value for the variable a and b