-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.js
More file actions
19 lines (14 loc) · 598 Bytes
/
Copy path2.js
File metadata and controls
19 lines (14 loc) · 598 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Predict and explain first BEFORE you run any code...
// this function should square any number but instead we're going to get an error
// Prediction: SyntaxError — a function parameter must be a valid identifier, not a number literal.
// Original broken code:
// function square(3) {
// return num * num;
// }
// Error message: SyntaxError: Unexpected number
// Explanation: `3` is a number literal and cannot be used as a parameter name.
// Parameters must be valid identifiers (variable names).
// Fix: use a named parameter like `num`.
function square(num) {
return num * num;
}