UndefinedVsNull.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. //
  6. // Test Equals operator with abstract equality comparison algorithm (ES3.0: S11.9.1, S11.9.3)
  7. //
  8. if (undefined == null)
  9. WScript.Echo("Algorithm says equivalent");
  10. else
  11. WScript.Echo("Objects are not equivalent");
  12. //
  13. // Test Strict Equals operator (ES3.0: S11.9.4)
  14. //
  15. if (undefined === null)
  16. WScript.Echo("Same instance");
  17. else
  18. WScript.Echo("Different instances");
  19. if (undefined === undefined)
  20. WScript.Echo("Same instance");
  21. else
  22. WScript.Echo("Different instances");
  23. if (null === null)
  24. WScript.Echo("Same instance");
  25. else
  26. WScript.Echo("Different instances");
  27. function dump(a, index)
  28. {
  29. var value = a[index];
  30. if (value === undefined)
  31. {
  32. WScript.Echo("'undefined'");
  33. }
  34. else if (value === null)
  35. {
  36. WScript.Echo("'null'");
  37. }
  38. else
  39. {
  40. WScript.Echo(value);
  41. }
  42. }
  43. //
  44. // Create an array and grow it, ensuring that all empty slots are properly set to 'undefined'
  45. //
  46. var a = new Array(2);
  47. dump(a, 0);
  48. dump(a, 1);
  49. dump(a, 10);
  50. a[10] = 'A';
  51. dump(a, 10);
  52. dump(a, 5);