JavaScript JavaScript Loops, Arrays and Objects Tracking Data Using Objects Accessing All of the Properties in an Object

Ali Abbas
Ali Abbas
8,772 Points

My solution code is not working. Why?

challenge task 1 of 2

var shanghai = {
  population: 14.35e6,
  longitude: '31.2000 N',
  latitude: '121.5000 E',
  country: 'CHN'

for (key in shanghai) {
<!DOCTYPE html>
  <meta charset="utf-8">
  <title>JavaScript Objects</title>
<script src="script.js"></script>

1 Answer

Steven Parker
Steven Parker
205,164 Points

You should have gotten this message: "Bummer: There was an error with your code: ReferenceError: Strict mode forbids implicit creation of global property 'key'":

for (let key in shanghai) {    // explicitly declare with "let" or "var"
Ali Abbas
Ali Abbas
8,772 Points

Perfect. Thanks for your reply.