What is wrong with this code?
```js
x = 5;
```
B
It declares a global variable implicitly, which is bad practice
C
It uses const incorrectly
D
It will throw a syntax error
Analysis & Theory
Assigning a value without `let`, `const`, or `var` creates a global variable, which is a bad practice.
What is the issue with this code?
```js
let x = 5;
let x = 10;
```
B
You can’t reassign a `let` variable
C
You can’t redeclare a `let` variable in the same scope
D
This creates a constant
Analysis & Theory
You can't redeclare a `let` variable within the same scope.
Why is `==` sometimes problematic in JavaScript?
A
It performs strict comparison
B
It throws errors on type mismatch
C
It allows type coercion which may cause bugs
D
It cannot be used with strings
Analysis & Theory
`==` performs type coercion, which can lead to unexpected comparisons like `0 == '0'` being `true`.
What happens if you forget to use `break` in a `switch` statement?
A
Only the matching case runs
C
All cases after the matching one run
Analysis & Theory
Without `break`, the code continues running through the following cases (fall-through).
What mistake is commonly made with `this` in object methods?
A
`this` always refers to the object
B
`this` is undefined in strict mode
C
`this` refers to the global object unexpectedly
D
`this` refers to the method name
Analysis & Theory
In regular functions (not arrow), `this` may refer to `window` or `global` if not bound correctly.
Which is a mistake when using `const`?
A
Modifying properties of a const object
B
Declaring constants in all caps
C
Trying to reassign the variable
Analysis & Theory
You can't reassign a `const` variable, though its object/array contents can still be modified.
What is a risk of using `eval()` in JavaScript?
B
It increases memory usage
C
It creates security and performance issues
D
It prevents event handling
Analysis & Theory
`eval()` can run arbitrary code, which is a major security and performance risk.
Why might this result in an error?
```js
console.log(a);
let a = 5;
```
B
`a` is hoisted but not initialized
Analysis & Theory
`let` declarations are hoisted but not initialized, so accessing them before declaration throws a `ReferenceError`.
Which is a mistake when dealing with arrays?
A
Using `push()` to add items
B
Using `length` to check size
C
Using `for...in` to iterate
D
Using `for...of` with arrays
Analysis & Theory
`for...in` is for object keys and may behave unexpectedly with arrays. Use `for` or `for...of` instead.
What can happen if you forget to return a value in a function?
C
It returns the last value
Analysis & Theory
If no return statement is used, the function returns `undefined` by default.