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

  • Home
  • SEARCH
  • 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 210389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:00:03+00:00 2026-05-11T18:00:03+00:00

We have a JSON response which can contain null values (e.g. { myValue: null

  • 0

We have a JSON response which can contain null values (e.g. { myValue: null }) – we assign this value to a textbox on a form: (actually, we use JQuery, but this is equivalent

var nullString = null;
document.getElementById('myInput').value = nullString;

If we assign this value to an HTML textbox value, the behaviour seems browser-dependent:

  • Firefox and Chrome both display an empty text box, and when you read ‘value’ back you get null.

  • IE puts the string ‘null’ into the text box, and when you read ‘value’ back, you get the string “null” (i.e. setting ‘value’ and reading it back has modified the data)

(It’s here: http://jsbin.com/uleno/edit if anyone wants to try it)

Which browser is doing the right thing here, or is this undefined behaviour? And is there a cleverer more elegant workaround than doing a lot of (myValue == null ? ” : myValue) stuff?

  • 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-11T18:00:03+00:00Added an answer on May 11, 2026 at 6:00 pm

    What’s actually happening is the null object is being stringified, like null.toString(). In an alert() message box, the browser usually interprets the object instead of simply stringifying it, so the result will be different. And, of course, browsers (especially IE) interpret and stringify differently.

    For what it’s worth, there is a logic to returning null when a string is expected. Whatever is returning this value probably does so in order to provide a false value for easy conditional testing, while still indicating that the result is empty rather than, eg undefined. DOM methods that return collection objects do the same. Further, while an empty string literal (”) is a false value, an empty String object (new String(”)) is not; and the latter can be created from the former accidentally with further processing. So the “safe” way to prevent the consuming code from accidentally discarding a valid string is to return a string literal or String object in one case, and null in another.

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

Sidebar

Ask A Question

Stats

  • Questions 179k
  • Answers 179k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you import sys, it contains a list of the… May 12, 2026 at 3:49 pm
  • Editorial Team
    Editorial Team added an answer I would go with Option 1, i.e. partition Dataset 2.… May 12, 2026 at 3:49 pm
  • Editorial Team
    Editorial Team added an answer Take a look at both, and see which syntax suites… May 12, 2026 at 3:49 pm

Related Questions

Let's assume, for instance, an xHTML document as below: <html> <head> </head> <body> <div
Here is my question, Would it be possible, knowing that classic asp support server-side
Edit #2: Does anyone have a good method of testing the middle of a
I am using Ext.data.Store to call a PHP script which returns a JSON response

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.