برنامه نویسی
متغیرها – انجمن DEV

پیشنهاد ویژه
[button color="primary" size="big" link="https://nabfollower.com/buy-real-follower/" icon="" target="true" follow="false"]خرید فالوور واقعی[/button][button color="primary" size="big" link="https://nabfollower.com/buy-instagram-like/" icon="" target="true" follow="false"]خرید لایک اینستاگرام[/button][button color="primary" size="big" link="https://nabfollower.com/buy-instagram-views/" icon="" target="true" follow="false"]خرید ویو اینستاگرام[/button][button color="primary" size="big" link="https://nabfollower.com/" icon="" target="true" follow="false"]خرید فالوور اینستاگرام[/button]
- متغیرها در جاوا اسکریپت محفظه هایی برای ذخیره مقادیر داده ها هستند.
- آنها با استفاده از
var
،let
، یاconst
کلید واژه ها. - متغیرهای اعلام شده با
var
دارای دامنه تابع یا دامنه جهانی هستند، در حالی که آنهایی که با آن اعلام شده اندlet
یاconst
دارای محدوده بلوک - استفاده از آن توصیه می شود
let
یاconst
برای اعلامیه های متغیر برای جلوگیری از مسائل مربوط به محدوده و بالا بردن.
// Variable declaration with var (function-scoped)
var firstName = "John";
console.log(firstName); // Output: John
// Variable declaration with let (block-scoped)
let lastName = "Doe";
console.log(lastName); // Output: Doe
// Variable declaration with const (block-scoped constant)
const age = 30;
console.log(age); // Output: 30