কম্পিউটার টিউটোরিয়াল

জাভাস্ক্রিপ্টে বড় সংখ্যা সংরক্ষণে + অপারেটর এর আচরণ এবং BigInt() ব্যবহার


জাভাস্ক্রিপ্টে বড় সংখ্যা সংরক্ষণ করতে + অপারেটর না ব্যবহার করে BigInt() ব্যবহার করুন। + অপারেটর ব্যবহার করলে প্রিসিশন (precision) লস হবে।

মনে করুন নিচের বড় সংখ্যাটি BigInt() দিয়ে সংরক্ষণ করছি −

console.log("Loss of precision with + operator..")

উদাহরণ

নিচে কোডটি দেওয়া হলো −

var stringValue1="100"; console.log("The integer value="); console.log(+stringValue1); var stringValue2="2312123211345545367"; console.log("Loss of precision with + operator..") console.log(+stringValue2); const storeLongInteger=BigInt("2312123211345545367"); console.log("No loss of precision with BigInt()"); console.log(storeLongInteger);

প্রোগ্রাম চালাতে হলে নিচের কমান্ড ব্যবহার করতে হবে −

node fileName.js. 

এখানে, আমার ফাইল নেম demo212.js।

আউটপুট

কনসোলে আউটপুট নিচের মত −

PS C:\Users\Amit\JavaScript-code> node demo213.js The integer value= 100 Loss of precision with + operator.. 2312123211345545000 No loss of precision with BigInt() 2312123211345545367n

  1. জাভাস্ক্রিপ্ট console.log() উদাহরণসহ

  2. জাভাস্ক্রিপ্ট Numbers উদাহরণ

  3. জাভাস্ক্রিপ্ট স্প্রেড অপারেটর

  4. জাভাস্ক্রিপ্টে DOM-রিলেটেড ভেরিয়েবল কনসোল.লগ (console.log) করা