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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:09:30+00:00 2026-05-31T11:09:30+00:00

I have a function along the lines of the following: doSomething: function () {

  • 0

I have a function along the lines of the following:

    doSomething: function () {
        var parent = null;

        if (this === null) {
            parent = 'some default value';
        } else {
            parent = this.SomeValue();
        }
    }

Could parent ever be set to ‘some default value’ or is the check for null superfluous?

Alternatively, what if I used the less restrictive:

    doSomething: function () {
        var parent = this ? this.SomeValue() : 'some default value';
    }

Could parent ever be set to ‘some default value’ in this case?

  • 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-31T11:09:31+00:00Added an answer on May 31, 2026 at 11:09 am

    In non-strict mode, this has undergone an Object(this) transformation, so it’s always truthy. The exceptions are null and undefined which map to the global object. So this is never null and always truthy, making both checks superfluous.

    In strict mode, however, this can be anything so in that case you’d have to watch out. But then again you have to opt in for strict mode yourself, so if you don’t do that there are no worries.

    (function() {               return this; }).call(null); // global object
    (function() { "use strict"; return this; }).call(null); // null
    

    The specification of ES5 says:

    The thisArg value is passed without modification as the this value. This is a change from Edition 3, where a undefined or null thisArg is replaced with the global object and ToObject is applied to all other values and that result is passed as the this value.

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

Sidebar

Related Questions

I have something along the lines of the following: var request = require('request'), express
I have written a pgsql function along the lines of what's shown below. How
i have created a module with this among others this function in it: <?php
I have the following function call inside a jsp page. jQuery(function($){ $(#product).mask(99/99/9999,{placeholder: }); });
Say that have the following CTE that returns the level of some tree data
I have some VERY inefficient code in which many lines appear 4 times as
I am trying to do something along the lines of the following: class Test
I have the following recursive function that is used to search down a hierarchical
I have the following function inside my HomeController class: public class HomeController : Controller
i have a c function which returns a long double . i'd like to

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.