irmantas_radavicius

Untitled

Oct 24th, 2021
672
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getStyle1(id){
  2.     if ((typeof id == "string") && (id)){
  3.         let myElement = document.getElementById(id);
  4.         if (myElement){ // null check
  5.             return myElement.style;
  6.         }
  7.     }
  8. }
  9. function getStyle2(id){
  10.     // input VALIDATION    
  11.     if ((typeof id != "string") || (!id)){
  12.         return undefined;
  13.     }  
  14.     // algorithm
  15.     let output;
  16.     let myElement = document.getElementById(id);
  17.     if (myElement){ // null check
  18.         output = myElement.style;
  19.     }  
  20.     // output  
  21.     return output;
  22. }
  23.  
  24. let a, b;
  25. if ((typeof a == typeof b) && (a == b)){ // a === b
  26. }
  27. if (a == b){ // types do not match ?!
  28. }
  29.  
  30. console.log(0 == 0);
  31. console.log("0" == 0);
  32. console.log("0" === 0);
  33.  
  34. console.log(0 != 0);
  35. console.log("0" != 0);
  36. console.log("0" !== 0);
  37.  
  38. /*
  39. // validation
  40.  
  41. console.log(isNaN(NaN));
  42. console.log(isFinite(NaN), isFinite(Infinity), isFinite(-Infinity));
  43.  
  44. let variable = "";
  45. if (variable){
  46.     console.log("True");
  47. } else {
  48.     console.log("False");
  49. }
  50. if (typeof variable != "number"){
  51.     // null? undefined?
  52.     if (variable != null){ // if (variable)    
  53.     }
  54.     if (variable != undefined){ // if (variable)
  55.     }
  56. }
  57.  
  58. // type is object
  59. if (typeof variable == "object"){
  60.     // null? undefined?
  61. }
  62. if ((typeof variable == "object") && (variable)){
  63.     // Ok
  64. }
  65.  
  66. // type is number
  67. if (typeof variable == "number"){
  68.     // NaN? Infinity?
  69. }
  70. if ((typeof variable == "number") && (isFinite(variable))){
  71.     // Ok
  72. }
  73. */
  74.  
  75. /*
  76. // four horsemen of JS
  77. // "niekas", neradau, nėra, tuščia
  78. let myElement = document.getElementById("manoId");
  79. console.log(myElement, typeof myElement);
  80. if (myElement != null){
  81.     let myStyle = myElement.style;
  82. }
  83.  
  84. // begalybė ("labai labai labai daug")
  85. let bigNumber = 0;
  86. bigNumber = 1 / 0;
  87. console.log(bigNumber, typeof bigNumber);
  88.  
  89. // ne skaičius (not a number)
  90. let anyNumber = "du" * 2;
  91. console.log(anyNumber, typeof anyNumber);
  92.  
  93. // neapibrėžta, nepasakyta, nenurodyta
  94. let something;
  95. console.log(something, typeof something);
  96. */
  97.  
  98.  
  99. /*
  100. // operator ? :
  101. let x = 1010;
  102. console.log("Number " + x + " is " + ((x % 2) ? "odd" : "even"));
  103.  
  104.  
  105. let output = "Number " + x + " is ";
  106. if (x % 2){
  107.     output += "odd";
  108. } else {
  109.     output += "even";
  110. }
  111. console.log(output);
  112. */
RAW Paste Data