0
0
Javascriptprogramming~10 mins

Variable declaration using const in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Variable Declaration Using const
📖 Scenario: You are creating a simple program to store information about a favorite fruit. You want to make sure the fruit name does not change accidentally.
🎯 Goal: Learn how to declare a variable using const in JavaScript and understand that its value cannot be changed later.
📋 What You'll Learn
Declare a variable using const
Assign a string value to the const variable
Try to change the value (to see what happens, but this will be commented out)
Print the value of the const variable
💡 Why This Matters
🌍 Real World
Using <code>const</code> helps keep important values safe from accidental changes in programs, like fixed settings or names.
💼 Career
Understanding <code>const</code> is essential for writing reliable JavaScript code in web development and many programming jobs.
Progress0 / 4 steps
1
Declare a const variable
Declare a variable called favoriteFruit using const and assign it the value "Apple".
Javascript
Need a hint?

Use const favoriteFruit = "Apple"; to declare the variable.

2
Add a comment about changing the variable
Add a comment below the declaration explaining that favoriteFruit cannot be changed because it is declared with const.
Javascript
Need a hint?

Write a comment starting with // explaining the variable is constant.

3
Try to change the const variable (commented out)
Add a line below the comment that tries to change favoriteFruit to "Banana", but comment it out so the program does not break.
Javascript
Need a hint?

Write // favoriteFruit = "Banana"; to show the change attempt is commented out.

4
Print the value of the const variable
Write a line to print the value of favoriteFruit using console.log.
Javascript
Need a hint?

Use console.log(favoriteFruit); to print the value.