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

The Archive Base Latest Questions

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

In C# you can do the following: string y = null; string x =

  • 0

In C# you can do the following:

string y = null;
string x = y ?? "sup stallion"; //x = "sup stallion" since y is null.

Where The ?? operator is the null-coalescing operator.

And in Javascript I’ve seen something similar:

var headers;
var myHeader = headers || {'Content-type':'text/plain'}; //myHeaders = {'Content...

I’ve also seen: (The 2nd code snippet on the page)

var headers;
var myHeader = headers | {'Content-type':'text/plain'};

Is there a difference between the two? What is this pattern called…default parameter?

  • 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-31T19:30:56+00:00Added an answer on May 31, 2026 at 7:30 pm

    || is a logical or. It returns the first truthy operand* (the last value evaluated). So

    var myHeader = headers || {'Content-type':'text/plain'};
    

    Returns “headers” if it’s truthy (and if it’s null or undefined, that value is coreced into “false”). If it’s falsey, it returns the second operand. I don’t believe this has a very specific name in javascript, just something general like “default argument value”.

    | is a bitwise or. It is a mathematical operation and does something completely different. That operator doesn’t even make sense here (and it will generally just produce 0 as a result). Wherever you saw that, it was surely a typo, and they meant to use logical or.

    So go with that first method (a = b || c).

    * “Logical or” is also known as “logical disjunction” or “inclusive disjunction”. Javascript, like all programming languages, evaluates logical statements using short-circuit evaluation. With logical-or expressions, it evaluates each operand for truthiness and stops on the first true one (and returns that value). If there are no truthy operands, it still had to go through all of them, so it returns the last operand, still the last one it evaluated. Logical and (&&) is similarly short-circuited by stopping on the first falsey operand.

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

Sidebar

Related Questions

How can I get the following string readable? var sc = unescape( %u9090%u19eb%u4b5b%u3390%u90c9%u7b80%ue901%u0175%u66c3%u7bb9%u8004%u0b34%ue2d8%uebfa%ue805 %uffe2%uffff%u3931%ud8db%u87d8%u79bc%ud8e8%ud8d8%u9853%u53d4%uc4a8%u5375%ud0b0%u2f53%ud7b2
Can anyone explain why the following occurs: String.Format(null, foo) // Returns foo String.Format((string)null, foo)
How can I construct the following string in an Excel formula: Maurice "The Rocket"
I have the following string: cn=abcd,cn=groups,dc=domain,dc=com Can a regular expression be used here to
Given the following: String s = The The The the the the; How can
Can't understand why the following takes place: String date = 06-04-2007 07:05; SimpleDateFormat fmt
I can use the following codes to trim a string: -(void) aMethod { //
If I have a hashmap containing the following: Hashmap contains (String, String) How can
How can I achieve the following with a format string: Do 01.01.2009 ? It
In Oracle, I can use the following: String query = { ? = call

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.