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 6818183
In Process

The Archive Base Latest Questions

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

I have a situation where I declare an object var o = null; Then,

  • 0

I have a situation where I declare an object var o = null;

Then, I pass it into a function, do stuff and maybe assign an object to it.

Later on, I execute parse(o.page).
If o is null, then I get “TypeError: o.page is null”,
and the program stops there because I’m trying to get the property of a null value.

I know one solution could be to initially assign null to all of o‘s properties.

Just wondering if there is a more subtle way to handle this error.
because I would like to handle parse1(o); and parse2(o.page1) where o can be null.

  • 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-26T21:08:49+00:00Added an answer on May 26, 2026 at 9:08 pm

    You could use the ternary operator to do this:

    parse2(o ? o.page1 : null)
    

    There is no way to get o.page to work on its own when o is null.

    Other ways exist, for example returning {} instead of null, as calling nonexistent properties yields undefined instead of throwing an error.

    Generally speaking, avoiding a situation where invalid calls linger in your code is recommendable. Either you check the return value before you use it (like above), or you don’t return values that can invalidate subsequent code.

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

Sidebar

Related Questions

We have a situation where users are allowed to upload content, and then separately
i have JavaScript components, that has following architecture: var MyComponent = function(params) { setup(params);
For object instances we can have their class declare some protocol conformance as in:
Okay, so I have this LINQ to SQL situation. I have a DataContext object
You may have run into situations wherein you declare a certain enum and you
Here is the situation: I have a table value function with a datetime parameter
i have situation like this: class IData { virtual void get() = 0; virtual
I have situation, where running a query that filters by an indexed column in
I have situation in which I read a record from a database. And if
I have situation where I need to change the order of the columns/adding new

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.