JavaScript Are there any meaningful use cases to assign undefined to a variable?

There are null and undefined in JavaScript. Are there any meaningful use cases of assigning undefined to a variable?

Answer:1

Yes.

When a property had a value and now you want it to have none, you usually have those choices:

delete:

delete obj.prop;

Problem: it has very big performance impacts. It is one of the biggest performance killers in an otherwise well designed JS program. Track it and be sure to never use it when performance matters (note that the impact isn't just located where you delete the property but also where you read or write other properties of the object later on, including when calling methods).

set the value to null:

obj.prop = null;

This only makes semantic sense when the expected type of the value is "object" (or sometimes "string"). Note that there's a semantic difference between null (i.e. no object) and undefined (i.e. value unset).

set the value to NaN:

obj.prop = NaN;

You won't use this for anything except numbers (but then it can make a ton of sense, depending on the specific use case).

set the value to undefined:

obj.prop = undefined;

This is the best choice in most other cases. It also plays nicely with the usually right way to test whether an argument or argument's property has been set, that is to check options.something === undefined.

Answer:2

Input: seconds, Output: grammatically correct, formatted time (with words spelled out). So far I managed to get as far as going from say 40044373 to 1 year, 98 days, 5 hours, 37 minutes, 1 second - ...

Input: seconds, Output: grammatically correct, formatted time (with words spelled out). So far I managed to get as far as going from say 40044373 to 1 year, 98 days, 5 hours, 37 minutes, 1 second - ...

  1. commas right now

I searched for a solution of passing a get variable obtained from index.php page to included.php file[ loaded by javascript ]. A nice solution by php require function is given Pass and print a $_GET ...

I searched for a solution of passing a get variable obtained from index.php page to included.php file[ loaded by javascript ]. A nice solution by php require function is given Pass and print a $_GET ...

I want JQuery function to return me the value inside the 'data-tabconfig' <li class="tab-add" data-tabconfig="#{layoutBean.maxTabs}"> I can easily get it if I call onclick function. $(this)....

I want JQuery function to return me the value inside the 'data-tabconfig' <li class="tab-add" data-tabconfig="#{layoutBean.maxTabs}"> I can easily get it if I call onclick function. $(this)....

  1. find data value from percentile
  2. find data value jquery
  3. find data value
  4. find data value matlab
  5. r find value in dataframe
  6. find value in dataframe
  7. find value data r
  8. find value data type
  9. find data attribute value jquery
  10. find data-id value in jquery
  11. find percentile data value calculator
  12. find the data value that corresponds to each percentile
  13. javascript find data value
  14. find minimum data value
  15. find data set value
  16. how to find data value in statistics
  17. find element with data value jquery
  18. how to find data value with z score
  19. find max value data
  20. javascript find data attribute value

I am using extjs 5 on web app using sencha CMD layout (mvvm) and would like to bind a store (for labels) to filter list in my view grid the viewModel store definition is: stores: { labelContacts:...

I am using extjs 5 on web app using sencha CMD layout (mvvm) and would like to bind a store (for labels) to filter list in my view grid the viewModel store definition is: stores: { labelContacts:...