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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:02:45+00:00 2026-06-01T16:02:45+00:00

if (typeof operand1 != undefined && operand1 == operand2) { } Above is an

  • 0
if (typeof operand1 != "undefined" && operand1 == operand2) {
}

Above is an if statement that checks for the equality between operand1 and operand2, where operand1 may be undefined under some scenario. I wonder if the typeof operand1 != "undefined" is unnecessary.

  • 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-06-01T16:02:46+00:00Added an answer on June 1, 2026 at 4:02 pm

    Because you use the == operator and not the === operator, it’s unnecessary only if operand2 will never be null.

    But you can change the if statement to use the === operator which then will pass only if operand2 “really equals” to operand1, meaning operand2 is undefined as well.

    You can read more about it here:
    Which equals operator (== vs ===) should be used in JavaScript comparisons?

    A fiddle that shows what was written here.


    In the Data Baseworld, null(or undefined) is nothing, which means you can’t compare it to anything.

    SQL example:

    SELECT *
    FROM   table_name t
    Where  t.operand1 = null
    

    is an error because nothing equals to null, and null doesn’t equal to anything, it just doesn’t exist.

    In javascript it is not like that, you can compare things to null and undefined, but you have to be careful with TypeErrors, like with this:

    var x;
    x.foo; // TypeError!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a difference between typeof value === undefined and value === undefined ?
Founded that: typeof(System.Enum).IsClass == false It's become strange that System.Enum has also .IsValueType ==
When using ECMAScripts typeof on plugin elements (i.e. embed or object ), Safari &
I get an undefined reference to 'typeof'-error compiling and linking this: #include <stdio.h> #include
I am trying to convert some Verilog code that produces a slower clock from
typeof(Nullable<>) public static bool IsNullableType(Type t) { return t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>); }
Possible Duplicate: typeof for RegExp I have a routine that is testing to see
// HomeController.cs [AutoMap(typeof(Test), typeof(TestViewModel))] public ActionResult Index() { var tests = new List<Test>(); tests.Add(new
I have the following: [ServiceContract] [ServiceKnownType(typeof(ActionParameters))] [ServiceKnownType(typeof(SportProgram))] [ServiceKnownType(typeof(ActionResult<SportProgram>))] public interface ISportProgramBl { [OperationContract] IActionResult<ISportProgram>
ParameterExpression parameter = Expression.Parameter(typeof(Product), x); MemberExpression Left = Expression.MakeMemberAccess(parameter, typeof(Product).GetProperty(Name)); ConstantExpression Right = Expression.Constant(value,

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.