Skip to content

Instantly share code, notes, and snippets.

@szhu
Last active February 10, 2023 20:34
Show Gist options
  • Save szhu/a3e1971af7362f7a49c854d5615cd009 to your computer and use it in GitHub Desktop.
Save szhu/a3e1971af7362f7a49c854d5615cd009 to your computer and use it in GitHub Desktop.
[object Object]

This code:

1  formResults = { ... };
2  console.log("first name: " + formResults.firstName);
3  console.log("last name: " + formResults.lastName);
4  console.log("email: " + formResults);

has the following output:

first name: John
last name: Doe
email: [object Object]

The last line of output is incorrect. It is caused by line 4, where we're trying to print the entire formResults object, but we actually just want to print the email.

Line 4 was probably meant to be:

4  console.log("email: " + formResults.email);

But when we fix it, we still get the same output:

first name: John
last name: Doe
email: [object Object]

huh???


Turns out, someone is trolling by filling out the form with [object Object] as their email address.

formResults = { firstName: "John", lastName: "Doe", email: "[object Object]" };
console.log("first name: " + formResults.firstName);
console.log("last name: " + formResults.lastName);
console.log("email: " + formResults.email);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment