Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7505463
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:55:08+00:00 2026-05-29T21:55:08+00:00

This is basically a theoretical question on the way the decoding of a JSON

  • 0

This is basically a theoretical question on the way the decoding of a JSON script takes place. I am new to JSON and JavaScript, so was taking a tutorial. It gave me a few example codes to work on. I found this out because of a mistake I committed. The example code was this–

<html>
<body>
<h2>Create Object from JSON String</h3>
<p>First Name: <span id="fname"></span></p> 
<p>Last Name: <span id="lname"></span></p>
<script type="text/javascript">
var employees = [
{ "firstName" : "John" , "lastName" : "Doe" }, 
{ "firstName" : "Anna" , "lastName" : "Smith" }, 
{ "firstName" : "Peter" , "lastName" : "Jones" }, ];
employees[1].firstName="Jonatan";
employees[2].lastName="Holla";
document.getElementById("fname").innerHTML=employees[1].firstName;
document.getElementById("lname").innerHTML=employees[2].lastName;
</script>

</body>
</html>

I would get the following output–

Create Object from JSON String

First Name: Jonatan

Last Name: Holla

But I accidentally committed a mistake by modifying line 14 of the code. Instead of “lname”, I had typed “fname” again.

document.getElementById("fname").innerHTML=employees[2].lastName;

It gave the following output–

Create Object from JSON String

First Name: Holla

Last Name:

Why did this happen? Agreed that calling getElementId on fname second time resulted in output of “Holla” in “First Name” field. But how did that statement negate any effect by the preceding statement? (ie, line 13)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:55:10+00:00Added an answer on May 29, 2026 at 9:55 pm

    It doesn’t negate it, it overwrites it.

    You first say: write “Jonatan” in fname. Then you say write “Holla” in fname. So you see at the end only “Holla”.

    And lname is empty because you don’t set it anymore – instead you set fname 2 times.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is basically a duplicate of this question , but the accepted answer was
This is basically the same question as Click items in select box, and then
Basically this is a question how to access local scope handler. I trying to
This will be a really theoretical question, just bear with me a bit. I
This is a question on what people think the best way to lay out
Im trying do this basically: var tr = document.createElement(tr); var td = document.createElement(td); td.appendChild(document.createTextNode('<input
What are the different types of encapsulation? Am I right in thinking this basically
I am trying to to build a Felix bundle in Eclipse. This basically includes
I know that in C#, if you write ~MyClass() , this basically translates to
This code basically translates characters based on position in one string to the character

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.