Skip to content

Commit 6ea69f1

Browse files
committed
Fix: renamed variable starting with a number to follow JS naming rules
1 parent e054a32 commit 6ea69f1

File tree

1 file changed

+12
-1
lines changed
  • Sprint-1/2-mandatory-errors

1 file changed

+12
-1
lines changed

Sprint-1/2-mandatory-errors/4.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,13 @@
11
const 12HourClockTime = "20:53";
2-
const 24hourClockTime = "08:53";
2+
// This line of code attempts to declare a constant variable named 12HourClockTime, but it results in a syntax error
3+
const 24hourClockTime = "08:53";
4+
5+
// While testing the code, the following error appeared in console:
6+
// SyntaxError: Invalid or unexpected token
7+
8+
// Why did this error occur? according to the MDN Web Docs: https://developer.mozilla.org/en-US/docs , a "SyntaxError: Invalid or unexpected token" occurs when JavaScript encounters code that doesn't follow proper syntax rules
9+
// In this case, the error happens because JavaScript does not allow variable names to start with numbers. Variable names (also called identifiers) must begin with a letter, underscore (_), or dollar sign ($)
10+
11+
// How to fix the error:
12+
const hour12ClockTime = "20:53";
13+
// These version follow JavaScript naming rules and will execute without errors

0 commit comments

Comments
 (0)