-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.js
More file actions
25 lines (16 loc) · 1.01 KB
/
Copy path2.js
File metadata and controls
25 lines (16 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Predict and explain first BEFORE you run any code...
// this function should square any number but instead we're going to get an error
// =============> write your prediction of the error here
// I predict that the error will be a SyntaxError because we are trying to declare a function with an invalid name. In JavaScript, function names cannot start with a number. By trying to declare a function named `square(3)`, we are violating this rule, which will result in a SyntaxError when the code is parsed.
function square(3) {
return num * num;
}
// =============> write the error message here
// SyntaxError due to an unexpected token or invalid function name.
// =============> explain this error message here
// This is because `square(3)` is not a valid function declaration in JavaScript, and the parser will not be able to understand it as a function definition.
// Finally, correct the code to fix the problem
// =============> write your new code here
function square(num) {
return num * num;
}