• divitus classitus

    In the book of CSS Mastery: Advanced Web Standards Solutions, there is a section about divitus and classitus.

    Using too many divs is often described as divitus and is usually a sign that your code is poorly structured and overly complicated. Some people new to CSS will try to replicate their old table structure using divs. But this is just swapping one set of extraneous tags for another. Instead, divs should be used to group related items based on their meaning or function rather than their presentation or layout.
  • Object vs Function

    
    
  • delete

    The delete operator can be used to remove a property from an object. It will remove a property from the object if it has one. It will not touch any of the objects in the prototype linkage.

  • || , && and !!

    && is guard operator aka "logical and", and || is default operator "aka logical or", we normally see the code like the following

    if ( condtion1 && condition2) { }
    if (condition1 || condition2) { }
    

    && is also know as guard operator. If first operand is truthy, the result is second operand, else result is is first operand. It can be used to avoid null reference.

    if (a){
      return a.memeber;
    } else {
       return a;
    }
    //this is the same
    return a && a.member
    

    || is aslo know is default operator. It is the opposite of && . If first operand is truethy, then result is first operand, else result is second operand. It can be used to fill in default value like the following, it is like ?? in csharp


    var last = input || {}; //{} is default value
    


    The !! operator can turn all value into boolean value, you can think of it boolean conversion operator. Keep in mind that truthy/falsy value is not boolean value. For example "hello" is truthy value. So you can write code like


    if ("hello")
    {
       alert("hello");
    }
    


    But "hello" itself is not boolean value, if you want to convert it into boolean value, you need to write


    function toBoolean(v)
    {
       if (v)
       {
         return true;
       }
       else
       {
          return false;
       }
    }
    
    
  • test

    test