question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why are null and undefined variables removed from params

See original GitHub issue

https://github.com/axios/axios/blob/638804aa2c16e1dfaa5e96e68368c0981048c4c4/lib/helpers/buildURL.js#L38

I would expect

let a
let b
axios({ params: { a, b })

To construct ?a=&b=

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:7
  • Comments:35 (4 by maintainers)

github_iconTop GitHub Comments

43reactions
vuoriliikaluomacommented, Feb 6, 2019

All of these are possible: { key: undefined } to ? (not included) { key: null } to ?key { key: '' } to ?key= { key: 'null' } to ?key=null

17reactions
ahtikcommented, Mar 31, 2018

The current behavior is actually in line with how JSON values are handled in JavaScript: JSON.stringify({ a:1, b:undefined, c:2 }) produces {"a":1,"c":2}

{a: undefined} is often used as a construct to ignore a JSON key. If you need “a=” then ‘’ seems to be semantically good enough.

Maybe {a: null} should be interpreted as “?a” param? But not undefined.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is the difference between null and undefined in ...
so basically null value means a variable has been explicitly set as (no value = null) or has been initialized and defined to...
Read more >
jQuery.param outputs "null" and "undefined" in the query string
null and undefined are perfectly acceptable values for input data. Their meaning is quite obviously: "in the structure, yet empty"... and the only...
Read more >
Difference between null and undefined in JavaScript
A null means the absence of a value. You assign a null to a variable with the intention that currently this variable does...
Read more >
NULL - Manual - PHP
Casting a variable to null using (unset) $var will not remove the variable or unset its value. It will only return a null...
Read more >
null - JavaScript - MDN Web Docs - Mozilla
null is not an identifier for a property of the global object, like undefined can be. Instead, null expresses a lack of identification,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found