-2

this code gives error which makes perfectly sense

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<script>
usestricr
</script>
</body>
</html>

but this doesn't why

<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<script>
"usestricr"
</script>
</body>
</html>

please help i'am noob in this

Stark
  • 3
  • 2
  • 1
    The first one gives you an error since you're accessing an undeclared variable. The second one doesn't give an error since you're **not** accessing an undeclared variable. You're creating a string then doing nothing with it. It's useless but valid JavaScript code. Why would it give an error? – VLAZ Aug 18 '20 at 07:04
  • "You're creating a string then doing nothing with it" oh! ok thanks VLAZ :) – Stark Aug 18 '20 at 07:24

1 Answers1

1

So that triggering strict mode in JS engines that support it wouldn’t cause errors to be thrown in older engines, the code to trigger it is just a string.

Putting a different string there is still just a string which is still syntactically valid even if semantically nonsense.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335