Automatically translated.View original post

variable # JavaScript

# Web Site Writing Basics

# javascript # variable

Variables in JavaScript are storage boxes used to store values that can be cited and used in programs. 📦

It's like labeling a box to hold things. Here, "box" is a variable and "thing" is a data value (e.g. numbers, text, logic).

Declaration of variables in JavaScript

Declaring variables in JavaScript can be done using three major keywords, each of which has different functional characteristics and scope (Scope):

1. Let

❇ Use for: Declare a variable whose value can be changed later

❇ Scope (Scope): It is a Block Scope type, meaning that the variable will be accessible only within the code block ({}) being declared.

❇ Example:

JavaScript

Let age = 30;

Age = 31; / / can change the value.

2. Const

❇ Use for: Declare Constant (Constant), which must default immediately and cannot be changed later

❇ Scope (Scope): It's a Block Scope type, just like let

❇ Example:

JavaScript

Const PI = 3.14159;

/ / PI = 3.14; / / An error will occur because the const cannot be changed.

❇ ⚠️ Exception: For Objects and Arrays declared with that const, the values inside Object or Array can also be changed (but not all new variable values can be configured)

3. Var

❇ Use for: It is an old-style keyword used to declare variables (before the ES6 / ES2015 era)

❇ Scope (Scope): It is Function Scope or Global Scope, which is overly flexible and can easily lead to errors.

❇ Instructions: To write modern JavaScript code, let and const are recommended instead of var to control the scope of variables more clearly.

2025/9/30 Edited to

... Read moreใน JavaScript นอกจากการประกาศตัวแปรด้วย let, const และ var แล้ว การเข้าใจเกี่ยวกับชนิดข้อมูลและวิธีการจัดการตัวแปรจะช่วยเพิ่มประสิทธิภาพในการเขียนโปรแกรมอย่างมาก ตัวแปรใน JavaScript สามารถเก็บข้อมูลได้หลายประเภท ได้แก่ ตัวเลข (Number), ข้อความ (String), ค่าตรรกะ (Boolean), อ็อบเจ็กต์ (Object), และอาเรย์ (Array) ซึ่งแต่ละประเภทสามารถนำไปใช้เพื่อแก้ไขปัญหาหรือพัฒนาฟังก์ชันต่าง ๆ ได้ ตัวอย่างเช่น การใช้ตัวแปรชนิดอาเรย์เพื่อเก็บรายการข้อมูล หรือใช้วัตถุเพื่อจัดเก็บข้อมูลหลายๆ ตัวในที่เดียว นอกจากนี้ ขอบเขตของตัวแปร (Scope) ถือเป็นสิ่งสำคัญที่ต้องเข้าใจ เพราะส่งผลต่อการเข้าถึงและการทำงานของตัวแปรในโปรแกรม ตัวแปรที่ประกาศด้วย let และ const จะมีขอบเขตแบบ block scope คือจะใช้ได้เฉพาะในบล็อกที่ประกาศเท่านั้น การใช้ scope แบบนี้ช่วยลดความผิดพลาดที่เกิดจากตัวแปรชนิดเดียวกันถูกประกาศซ้ำหรือใช้ผิดที่ ส่วน var มีขอบเขตแบบ function scope ซึ่งอาจส่งผลให้เกิดปัญหาด้านความชัดเจนของตัวแปร ถ้าไม่ระมัดระวัง การใช้ let และ const จึงถือเป็นแนวทางที่แนะนำใน JavaScript สมัยใหม่ เพราะช่วยให้โค้ดปลอดภัยและดูแลรักษาง่ายขึ้น เมื่อพูดถึง const ซึ่งเป็นค่าคงที่นั้น ควรจำไว้ว่าถึงแม้ตัวแปรจะไม่สามารถเปลี่ยนแปลงค่าตัวแปรได้โดยตรง แต่ถ้าเป็นอ็อบเจ็กต์หรืออาเรย์ที่ประกาศด้วย const ข้อมูลภายในยังสามารถเปลี่ยนแปลงหรือปรับปรุงได้ตามต้องการ นี่เป็นความสามารถพิเศษที่ผู้พัฒนาควรรู้เพื่อใช้ประโยชน์จาก const อย่างถูกต้อง ท้ายที่สุด การฝึกปฏิบัติและทดสอบการประกาศตัวแปรในโปรแกรมจริงจะช่วยให้เข้าใจการทำงานของแต่ละชนิดตัวแปรได้ชัดเจนขึ้น การเขียนโค้ด JavaScript อย่างมีประสิทธิภาพรวมถึงการเลือกใช้ตัวแปรชนิดที่เหมาะสมและการควบคุมขอบเขตตัวแปรจะช่วยลดบั๊กและทำให้โปรแกรมทำงานได้อย่างราบรื่น

Related posts

My Programming Interest Just Skyrocketed! 🚀
I just discovered something that has made my interest in programming explode to 1000000000000000%! 🤯 🎮 Learning Programming is Like a Game Adventure! From Python, Java, JavaScript, to HTML, there are all kinds of programming languages available, along with systematic topic courses. The learning p
Valder

Valder

2173 likes

A desk setup with a computer screen displaying the Khan Academy website, showing course categories like 'Careers' and 'Computer programming'. A pink lululemon water bottle is on the right. Text overlay reads 'how to learn for free' and 'SWIPE TO VIEW'.
A webpage for grow.google.com, asking 'What would you like to learn?' with options for career and business growth. It highlights free courses and certifications, providing tools and resources for skill development and career advancement.
A webpage for Khan Academy, titled 'My courses', showing various learning paths including 'Careers', 'Computer programming - JavaScript and the web', and 'Intro to computer science - Python'. It describes Khan Academy as a free resource for diverse subjects.
learn for free with these websites 🎀
‧°𐐪♡𐑂°‧₊ ⛄️ Learning new knowledge or skills can be completely free using these websites! It’s a great way to spend your free time ✨ Open University & Khan Academy is perfect for students wanting to enhance knowledge of content they already know to study, go ahead of content or learn knowl
peachiesuga ♡

peachiesuga ♡

6690 likes

A scenic view of a coastal town with white buildings and blue sea, featuring text overlay "3 websites for free tech certifications BEGINNER FRIENDLY".
A person in a straw hat looking at a white-washed coastal town, with text overlay "1. Google Skillshop Google Analytics Individual Qualification Google Ads Certifications".
A person looking at a white-washed coastal town with pink flowers, featuring text overlay "2. Microsoft Learn Microsoft Azure Fundamentals Power BI Data Analyst Associate".
3 websites for free tech certifications - beginner
1. Google Skillshop - What It Offers: Free certifications in Google products like Google Analytics, Google Ads, and Google Cloud. - Best For: Digital marketing, data analysis, and cloud computing beginners. - Key Certifications: - Google Analytics Individual Qualification
vedha | career tips (tech) 👩‍

vedha | career tips (tech) 👩‍

916 likes

These sites saved my brain in 2025 🧠💻
1. ChatHub I used to bounce between AI platforms, copy-pasting the same prompt over and over to compare answers. With ChatHub, I can talk to multiple AIs at the same time, in one clean interface. It’s honestly my go-to whenever I’m brainstorming content, writing study scripts, or just curious whi
emilie.studygram

emilie.studygram

563 likes

How I’d Learn JavaScript If I Were Starting Again
#javascript #coding #programming #tech #codingforbeginners
Aysha

Aysha

124 likes

#chinesefacereading #fy #fyp #personalitytype #face
kate__kali

kate__kali

15 likes

Pattern Variable Sewing Machine
#sewingmachine #stitchingmachine
Shoe & Leather Machines

Shoe & Leather Machines

9 likes

Where do I learn free coding online?
It’s FREE! DO IT! #coding #bootcamp #codingforbeginners #free #technology
CosmicMama8

CosmicMama8

17 likes

The image introduces "DUOLINGO DUPES TO LEARN HOW TO CODE (for free!)" with icons for Mimo, Encode, and Sololearn apps, set against a light blue background with floral patterns.
The image details the Mimo app, showcasing its icon, career paths like Full-Stack Developer and Python AI Developer, and a description of its courses in Python, SQL, JavaScript, and more.
The image highlights the Encode app, displaying its icon, a "LEARN TO CODE" interface, and lesson topics such as Swift Basics and Reusing Code, along with a description of its interactive lessons.
✨CALLING ALL THE TECH GIRLS 🖥️ ✨
Learning to code was never on my radar—until life nudged me in the right direction. As the granddaughter of a brilliant I.T. professional, I didn’t fully appreciate his advice to dive into tech until after his passing in 2021. Now, I’m honoring his legacy by teaching myself to code, one step at a t
✿ Jaide ✿

✿ Jaide ✿

142 likes

Best - FREE - coding sites
learning to code is important and a great look for your resume! plus it’s fun! ANYONE CAN LEARN! these are my favorite sites I’ve utilized to learn new skills! #codinggirl #codingforbeginners #embracevulnerability #shareyourthoughts #Lemon8Diary
LOLLIPOPAK

LOLLIPOPAK

2979 likes

free tech certifications - 3 websites
1. freeCodeCamp • Why it’s great: Offers free certifications in web development, data analysis, and machine learning. • Popular certs: Responsive Web Design, Data Analysis with Python, and JavaScript Algorithms. • Best for: Beginners starting with coding and tech basic
vedha | career tips (tech) 👩‍

vedha | career tips (tech) 👩‍

2175 likes

A man with tattoos and a cap sits at a desk, coding on a large monitor in a dimly lit room. Text overlays read 'SWIPE', 'Learning JavaScript?', and 'This is for YOU!', with a thinking emoji, promoting coding education.
A man with headphones and a cap codes at a desk with a large monitor displaying code. Text overlays read 'SWIPE', 'Break vs Continue', and 'In JS loops', with a thinking emoji, highlighting JavaScript loop concepts.
A man with headphones and a cap sits at a desk, coding on a large monitor in a bright room. Text overlays read 'Let's Discuss!' with a thinking emoji, inviting interaction about coding topics.
Coding W/ JavaScript?
As a software engineer w/ ADHD, understanding the difference between certain syntax keywords is critical, such as ‘continue’ and ‘break’ within JavaScript loops.💡 It’s almost like centering a <div> — it takes practice to feel confident in your abilities. 🛠️ When my mind gets stuck in a
Michael Burbank

Michael Burbank

13 likes

A woman smiles next to a paper showing an ATI TEAS score of 98% and a time spent of 02:30:22. Text asks, 'Struggling with your ATI TEAS Exam? Here's how your girl got a 98% with these Materials.'
A close-up of an ATI TEAS Individual Performance Profile showing an Adjusted Individual Total Score of 98.7% and an 'Exemplary' academic preparedness level. The test completion date of 1/9/2026 is circled.
A practice sheet for ATI TEAS 7 Science questions, displaying multiple-choice questions 1-7 and 11-12 on topics like fish respiration, cell biology, human physiology, and chemistry, with some answers highlighted.
Teas exam
Struggling with the TEAS? Let’s turn confusion into confidence and stress into high scores. 📚✨ DM me to start passing with ease. #TEASExam #FutureNurse #NursingStudent #NursingJourney #PreNursing
Examsnurse

Examsnurse

23 likes

Did you know??
That your phone logs your websites you visit even if they are deleted? Here I’m going to teach you how to access your website data, so that you can check and delete both yours (and others😉🤪) website history. #relationshiptips #Couple #toxicrelationship #Lemon8 #christmas
Kristin🔆🔍

Kristin🔆🔍

54 likes

A laptop displaying college statistics notes is open on a white desk, with a desktop monitor in the background showing the time and an inspirational quote. The notes on the screen cover probability concepts, including a binomial probability cheat sheet.
Detailed handwritten college statistics notes cover binomial and normal probability distributions. Topics include finding percentiles, calculating probabilities for various scenarios, and understanding sampling error, with examples and TI-84 calculator instructions.
Handwritten college statistics notes explain how to find the mean and standard deviation of random variables, identify distribution of sample means, and apply general addition and multiplication rules for probability, with various examples.
steal my college stats notes! pt. 2 💯📉📊
steal my college stats notes! pt. 2 💯📉📊 hello friends! here are some more notes from my college stats class last semester! because my professor let us bring a cheat sheet to class, i had to make sure my notes were clean. i needed to be able to flip through my notes and find each topic quickl
lia 💗

lia 💗

146 likes

Printable budget plannersAnd expense trackers
#biweeklybudget #lemon8challenge I know people especially the girls like to write out things , I know I do . Here are some expense trackers and budget planners you can save to your phone and print out. Or draw out I know I’ve done that before . But save this post so you can come back and look
🧿 Briana Jade Canter

🧿 Briana Jade Canter

54 likes

A person sits at a desk with a computer displaying code and a calendar, surrounded by a plant and a sun lamp, illustrating a focused self-study environment.
A tablet displays a digital planner with a detailed October calendar, showing scheduled study tasks, emphasizing setting clear goals and breaking them into milestones.
A laptop shows programming code and a ChatGPT explanation of linked lists, highlighting the use of quality online resources like videos or courses for learning complex topics.
Learn How To Self Study Like a Pro!!
Ready to master self-studying like a pro? 💻✨ It’s all about setting clear goals, finding the best resources, and sticking to a schedule that works for you. 📅 Don’t forget to test yourself along the way, those practice quizzes and flashcards are your secret weapons! 🧠 And if something feels off, tak
CompSkyy

CompSkyy

70 likes

A clear binder with colorful glitter and sequins, titled "Cash Stuffing Binder Sinking Funds." A hand holds the binder, showcasing a pink-toned divider with a road and streetlights.
A clear binder open to a divider labeled "Sinking Funds" with a pink road image. Text explains, "This binder is dedicated to expenses that come eventually, but not monthly."
A clear binder open to a divider labeled "Car Maintenance" featuring a pink beach scene. Text lists associated expenses: "Detailing, Repairs, Upgrades, Oil changes, etc."
Cash Stuffing Binder💵 Sinking Funds💕
Every dollar has a place ! On the road to financial freedom. Starting by getting serious and organized with my spending🩷 I personalized this binder for sinking funds. Picked photos I liked from Pinterest. Edited, printed, and laminated them. I plan on still adding some additional accessories as w
Keria🩷

Keria🩷

18 likes

A character sheet portrait of a smiling woman, a 52-year-old mom of seven, surrounded by elements reflecting her organized, resilient life. It highlights her journey balancing family, personal growth, and learning technology like Python, JavaScript, and SQL, with daily routines, goals, and affirmations for managing anxiety and ADHD.
🌹 From Python, JavaScript and SQL Books to Code Dreams: This Is Me
🌹 From Budget Books to Code Dreams: This Is Me This beautiful character-sheet portrait captures me being organized, resilient, and focused on growth. I am surrounded by planners, notebooks, coding references, roses, and inspirational reminders, I represent the perfect blend of determination and
mirandaperry05

mirandaperry05

1 like

Fixed rates are not directly impacted by the Bank of Canada rate announcement. #mortgages #bankofcanada #interestrates #money #canada
MortgageswithSamanthaPower🇨🇦

MortgageswithSamanthaPower🇨🇦

3 likes

Python Variable Names Explained (Avoid These Mista
Confused by Python code? 😵‍💫 The problem might be bad variable names. In this post, you’ll learn: ✔ What variable names are ✔ Rules you must follow ✔ Good vs bad examples ✔ Pro tips to write clean Python code Save this post 📌 and follow for more Python basics made easy 🐍✨ #Python #LearnPy
TechKeysX

TechKeysX

0 likes

Pattern Variable Sewing Machine
#sewingmachine #stitchingmachine #moccasins #moccasin
Shoe & Leather Machines

Shoe & Leather Machines

4 likes

The image displays the title 'Tech jobs Straight out of college + AVERAGE SALARY' over a desk setup with a laptop showing a scenic wallpaper and a monitor.
This image details the '1. Software Developer' role, including job description, skills, starting salary ($70,000-$90,000), and preparation tips, set against a background of stone steps and a blue sky.
The image presents information for '2. Data Analyst,' covering job duties, skills, starting salary ($60,000-$75,000), and preparation advice, overlaid on a street scene with buildings and people.
Tech jobs you can get in college
1. Software Developer - What You’ll Do: Design, code, test, and maintain software applications or systems, working on web apps, mobile apps, or backend systems. - Skills to Focus On: Programming languages (Python, Java, C++, JavaScript), Git, Agile methodologies. - Average Starting Sala
vedha | career tips (tech) 👩‍

vedha | career tips (tech) 👩‍

92 likes

Feeling hesitant about freelancing? I get it!
I remember those nerves about diving into something new. But trust me, the rewards are so worth pushing through the fear! If you're ready to take the leap but not sure where to start, here are some easy-to-start side hustles that will help you gain experience and build your portfolio: 👉🏻
Bria | Social Media Marketing

Bria | Social Media Marketing

28 likes

Tools Every Full-Stack Web Developer Should Know
#learntocode #codingforbeginners #fullstackdeveloper #techtips #webdevjourney
Aysha

Aysha

23 likes

Caregiver Calm Tip: Fixed vs. Variable
#Caregiver #Calm #budget #money
Cynthia

Cynthia

3 likes

🎮Try These Games When You are Free
🎮CodeCombat CodeCombat is an educational role-playing game that allows players to learn programming while having fun. In this game, players take on the role of a hero and progress through various levels by inputting code to control the hero's actions. It offers support for multiple progr
Capital&Crypto

Capital&Crypto

6 likes

A young woman with long blonde hair looks upwards, with the text "Best AI Tutor for Coding" overlaid. The Lemon8 logo and username @code.with.bootsel are visible at the bottom left.
Best AI Tutor for Coding
I’ve tried YouTube tutorials, online courses, and coding bootcamps - but nothing felt personal. Every platform threw videos and notes at me… but when I got stuck, I was still alone. That changed the moment I discovered BootSelf, the best AI tutor app for coding in 2025. 🚀 This app doesn’t ju
Code with BootSelf AI

Code with BootSelf AI

1 like

A dark blue background with text "5 MORE YOUTUBE CHANNELS PART 2 TO BOOST YOUR CODING SKILLS". A computer monitor displays a YouTube logo, coding language icons (HTML, Python, React, JavaScript), and a code snippet. Text at the bottom says "SWIPE TO UNLOCK CODING GOLD!".
A dark blue background featuring the YouTube channel "SuperSimpleDev" with its channel page displayed on a monitor. Text highlights its benefits: step-by-step beginner tutorials for HTML, CSS, JavaScript, teaching from scratch, practical web development, and a friendly style.
A dark blue background featuring the YouTube channel "EJ Media" with its channel page displayed on a monitor. Text highlights its benefits: beginner-friendly UI/UX and frontend projects, covering Tailwind CSS, animations, and landing pages, with modern, portfolio-ready projects.
5 More YouTube Channels Part 2
#codingforbeginners #learntocode #youtubecoding #webdevelopment #pythonforbeginners
Aysha

Aysha

65 likes

penny

penny

0 likes

Pattern Variable Sewing Machine
#sewingmachine #stitchingmachine #moccasins
Shoe & Leather Machines

Shoe & Leather Machines

3 likes

Pattern Variable Sewing Machine
#sewingmachine #stitchingmachine
Shoe & Leather Machines

Shoe & Leather Machines

1 like

$1099 Later… Here’s the Truth About the iPad Pro✨
$1099 might sound crazy for a tablet… but here’s why this iPad Pro became my ride-or-die as a work-from-home mom and student: ✨ It’s basically my laptop, sketchbook, planner, & notebook all in one I pair it with: — Apple Magic Keyboard (hello built-in trackpad & laptop vibes!) — Apple
Byaombe •••

Byaombe •••

8546 likes

Show on scroll website
Sample website with smooth scrolling and content showing on,y when is on screen. #CSS #html #javascript #webdevelopment
The Digital Mike

The Digital Mike

1 like

A pink desktop setup featuring an iMac displaying the Vimium C options page with settings for key mappings, search engines, and advanced features. Decorative items like a pink bunny figurine and yellow tulips in a vase are arranged around the monitor, creating a personalized workspace.
A promotional image for Vimium C, a keyboard shortcut tool, showing its Chrome Web Store listing with high ratings and over 40,000 users. It highlights the tool's ability to navigate, search, and manage browser tabs effortlessly using powerful keyboard shortcuts.
A guide to Vimium C commands, listing various navigation shortcuts like scrolling. It instructs users to type '?' for help and demonstrates how to use the browser's address bar (omnibox) to search history, bookmarks, and tabs by typing 'v ...'.
🍋 The ultimate keyboard shortcuts tool
‧°𐐪♡𐑂°‧₊ 🥯Boost your browsing efficiency with Vimium C, the ultimate keyboard-driven tool designed to improve your online experience without the need of a mouse! Perfect for uni students and young adults juggling multiple tabs and research tasks, Vimium C lets you navigate, search, and manage bro
peachiesuga ♡

peachiesuga ♡

144 likes

An image featuring Kim Kardashian in front of a Harvard University building, with text announcing Harvard's free online courses and listing 8 courses for 2025.
A screenshot of a Harvard webpage detailing the 'Artificial Intelligence in Business: Creating Value with Machine Learning' course, including start dates and a classroom photo.
A screenshot of a Harvard webpage for 'Data Science: Machine Learning,' showing course duration, time commitment, and that it is free and online.
If Harvard is trying to help people go to college for free, then I’m all for it, I wonder if this administration will look at these different specific types of careers as professional or not but then again if you go to these classes and graduate and get accredited from Harvard, who gives a fuck if
CORALOUW/🥇 achievements

CORALOUW/🥇 achievements

7 likes

An iPad displays a PDF on recursive programming, with a colorful keyboard and stylus. The image highlights a study tool for students, featuring the UPDF app icon and suggesting it's an essential study aid.
An iPad shows a PDF document alongside an AI assistant panel summarizing 'recursion in JavaScript'. Text indicates the AI can summarize entire PDFs and answer questions based on the material.
An iPad displays a scanned handwritten note converted to PDF, demonstrating how to turn physical paper into digital files for annotation, comparison, or editing. A physical notebook is also visible.
Study smarter not hard 🌸
Hey besties! Struggling with studying this semester? Let me show you how to work smarter, not harder. If you’ve got an iPad or laptop, you NEED to check out UPDF—this AI-powered PDF editor is a game-changer! Here’s why: ❤️ Annotation: Highlight, underline, and add notes to your PDFs—perfect for
Byaombe •••

Byaombe •••

96 likes

See more