Let and Const
Let and Const
π¨βπΌ We're building a shopping cart system. Some values will change as users
interact (like the cart total), while others stay constant (like tax rates and
product prices).
π¨ Open
and:
- Create a
constforTAX_RATEset to0.08 - Create a
letforcartTotalstarting at0 - Create
constvariables for product prices:bookPrice,muffinPrice, andlaptopPrice - Add items to the cart by updating
cartTotal - Try to reassign
TAX_RATEand see what TypeScript says
π° By convention, constants that represent fixed values are often UPPER_CASE:
const MAX_ITEMS = 100
const API_URL = 'https://api.example.com'
π MDN - const
This is the first exercise where you'll be exporting values for the tests! For
a reminder on how to do that, check out the previous
page.