Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getStyle1(id){
- if ((typeof id == "string") && (id)){
- let myElement = document.getElementById(id);
- if (myElement){ // null check
- return myElement.style;
- }
- }
- }
- function getStyle2(id){
- // input VALIDATION
- if ((typeof id != "string") || (!id)){
- return undefined;
- }
- // algorithm
- let output;
- let myElement = document.getElementById(id);
- if (myElement){ // null check
- output = myElement.style;
- }
- // output
- return output;
- }
- let a, b;
- if ((typeof a == typeof b) && (a == b)){ // a === b
- }
- if (a == b){ // types do not match ?!
- }
- console.log(0 == 0);
- console.log("0" == 0);
- console.log("0" === 0);
- console.log(0 != 0);
- console.log("0" != 0);
- console.log("0" !== 0);
- /*
- // validation
- console.log(isNaN(NaN));
- console.log(isFinite(NaN), isFinite(Infinity), isFinite(-Infinity));
- let variable = "";
- if (variable){
- console.log("True");
- } else {
- console.log("False");
- }
- if (typeof variable != "number"){
- // null? undefined?
- if (variable != null){ // if (variable)
- }
- if (variable != undefined){ // if (variable)
- }
- }
- // type is object
- if (typeof variable == "object"){
- // null? undefined?
- }
- if ((typeof variable == "object") && (variable)){
- // Ok
- }
- // type is number
- if (typeof variable == "number"){
- // NaN? Infinity?
- }
- if ((typeof variable == "number") && (isFinite(variable))){
- // Ok
- }
- */
- /*
- // four horsemen of JS
- // "niekas", neradau, nėra, tuščia
- let myElement = document.getElementById("manoId");
- console.log(myElement, typeof myElement);
- if (myElement != null){
- let myStyle = myElement.style;
- }
- // begalybė ("labai labai labai daug")
- let bigNumber = 0;
- bigNumber = 1 / 0;
- console.log(bigNumber, typeof bigNumber);
- // ne skaičius (not a number)
- let anyNumber = "du" * 2;
- console.log(anyNumber, typeof anyNumber);
- // neapibrėžta, nepasakyta, nenurodyta
- let something;
- console.log(something, typeof something);
- */
- /*
- // operator ? :
- let x = 1010;
- console.log("Number " + x + " is " + ((x % 2) ? "odd" : "even"));
- let output = "Number " + x + " is ";
- if (x % 2){
- output += "odd";
- } else {
- output += "even";
- }
- console.log(output);
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement