const කියන්නේ බොරුවක්ද?

Shamal3001

Well-known member
  • Sep 22, 2021
    7,096
    11,973
    113
    මචං අපිට ලුප් ඒකක්දී මෙහෙම const අගයන් වෙනස් කරන්න පුලවන් නේද?

    ඒතනදි const කියන්නේ නියතයක් නෙමෙයිනේ ?

    Code:
    const scores = [75, 80, 95];
    
    
    
    for (const score of scores) {
    
    
    
        scores[1] = 99;
    
        console.log(score);
    
    }
     

    හෙළයෙක්

    Well-known member
  • Apr 26, 2014
    49,287
    100,095
    113
    const කියන්නෙ නියතයක් තමා. const එකට ආයෙ මොකවත් Assign කරන්න බෑ. හැබැයි const එකට Assign කරපු variable එක ඇතුලෙ variable වෙනස් කරන්න පුළුවන්. එහෙමත් කරන්න බැරි නන් Immutable varibales එකක් යූස් කරන්න ඕනි. https://immutable-js.com/
     

    Cypress

    Well-known member
  • Jul 22, 2021
    16,109
    27,535
    113
    🥲 oya waradak karanawa @Shamal3001 machan.

    මචං අපිට ලුප් ඒකක්දී මෙහෙම const අගයන් වෙනස් කරන්න පුලවන් නේද?

    ඒතනදි const කියන්නේ නියතයක් නෙමෙයිනේ ?

    Code:
    const scores = [75, 80, 95];
    
    
    
    for (const score of scores) {
    
    
    
        scores[1] = 99;
    
        console.log(score);
    
    }
    reference eka maaru unada? naa ne? naa ne? :P
    ------ Post added on Nov 24, 2021 at 11:52 AM
     

    Sandy_Fdo

    Well-known member
  • Sep 12, 2021
    20,105
    23,323
    113
    const කියන්නෙ නියතයක් තමා. const එකට ආයෙ මොකවත් Assign කරන්න බෑ. හැබැයි const එකට Assign කරපු variable එක ඇතුලෙ variable වෙනස් කරන්න පුළුවන්. එහෙමත් කරන්න බැරි නන් Immutable varibales එකක් යූස් කරන්න ඕනි. https://immutable-js.com/
    Yes. Exactly.