1. The difference between Call, Apply and Bind can be explained with below examples, Call: The call() method invokes a function with a given this value and arguments provided one by one var employee1 = { firstName: "John", lastName: "Rodson" }; var employee2 = { firstName: "Jimmy", lastName: "Baily" };Read more

    The difference between Call, Apply and Bind can be explained with below examples,

    Call: The call() method invokes a function with a given this value and arguments provided one by one

    var employee1 = { firstName: "John", lastName: "Rodson" };
    var employee2 = { firstName: "Jimmy", lastName: "Baily" };
    
    function invite(greeting1, greeting2) {
      console.log(
        greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2
      );
    }
    
    invite.call(employee1, "Hello", "How are you?"); // Hello John Rodson, How are you?
    invite.call(employee2, "Hello", "How are you?"); // Hello Jimmy Baily, How are you?

    Apply: Invokes the function with a given this value and allows you to pass in arguments as an array

    var employee1 = { firstName: "John", lastName: "Rodson" };
    var employee2 = { firstName: "Jimmy", lastName: "Baily" };
    
    function invite(greeting1, greeting2) {
      console.log(
        greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2
      );
    }
    
    invite.apply(employee1, ["Hello", "How are you?"]); // Hello John Rodson, How are you?
    invite.apply(employee2, ["Hello", "How are you?"]); // Hello Jimmy Baily, How are you?

    bind: returns a new function, allowing you to pass any number of arguments

    var employee1 = { firstName: "John", lastName: "Rodson" };
    var employee2 = { firstName: "Jimmy", lastName: "Baily" };
    
    function invite(greeting1, greeting2) {
      console.log(
        greeting1 + " " + this.firstName + " " + this.lastName + ", " + greeting2
      );
    }
    
    var inviteEmployee1 = invite.bind(employee1);
    var inviteEmployee2 = invite.bind(employee2);
    inviteEmployee1("Hello", "How are you?"); // Hello John Rodson, How are you?
    inviteEmployee2("Hello", "How are you?"); // Hello Jimmy Baily, How are you?

    Call and apply are pretty interchangeable. Both execute the current function immediately. You need to decide whether it’s easier to send in an array or a comma separated list of arguments. You can remember by treating Call is for comma (separated list) and Apply is for Array.

    Whereas Bind creates a new function that will have this set to the first parameter passed to bind().

    See less
  2. Prototype chaining is used to build new types of objects based on existing ones. It is similar to inheritance in a class based language. The prototype on object instance is available through Object.getPrototypeOf(object) or **proto** property whereas prototype on constructors function is available tRead more

    Prototype chaining is used to build new types of objects based on existing ones. It is similar to inheritance in a class based language.

    The prototype on object instance is available through Object.getPrototypeOf(object) or **proto** property whereas prototype on constructors function is available through Object.prototype.

    Screenshot

    See less
  3. There are many ways to create objects in javascript as below Object constructor: The simplest way to create an empty object is using the Object constructor. Currently this approach is not recommended. var object = new Object(); Object's create method: The create method of Object creates a new objectRead more

    There are many ways to create objects in javascript as below

    1. Object constructor:

      The simplest way to create an empty object is using the Object constructor. Currently this approach is not recommended.

      var object = new Object();
    2. Object’s create method:

      The create method of Object creates a new object by passing the prototype object as a parameter

      var object = Object.create(null);
    3. Object literal syntax:

      The object literal syntax (or object initializer), is a comma-separated set of name-value pairs wrapped in curly braces.

      var object = {
           name: "Sudheer"
           age: 34
      };
      
      Object literal property values can be of any data type, including array, function, and nested object.

      Note: This is an easiest way to create an object

    4. Function constructor:

      Create any function and apply the new operator to create object instances,

      function Person(name) {
        this.name = name;
        this.age = 21;
      }
      var object = new Person("Sudheer");
    5. Function constructor with prototype:

      This is similar to function constructor but it uses prototype for their properties and methods,

      function Person() {}
      Person.prototype.name = "Sudheer";
      var object = new Person();

      This is equivalent to an instance created with an object create method with a function prototype and then call that function with an instance and parameters as arguments.

      function func() {};
      
      new func(x, y, z);

      (OR)

      // Create a new instance using function prototype.
      var newInstance = Object.create(func.prototype)
      
      // Call the function
      var result = func.call(newInstance, x, y, z),
      
      // If the result is a non-null object then use it otherwise just use the new instance.
      console.log(result && typeof result === 'object' ? result : newInstance);
    6. ES6 Class syntax:

      ES6 introduces class feature to create the objects

      class Person {
        constructor(name) {
          this.name = name;
        }
      }
      
      var object = new Person("Sudheer");
    7. Singleton pattern:

      A Singleton is an object which can only be instantiated one time. Repeated calls to its constructor return the same instance and this way one can ensure that they don’t accidentally create multiple instances.

      var object = new (function () {
        this.name = "Sudheer";
      })();
    See less
  4. Sometimes it is also typical to install Ghostscript, which gives additional features if you want to convert between an image format and PDF/postscript.

    Sometimes it is also typical to install Ghostscript, which gives additional features if you want to convert between an image format and PDF/postscript.

    See less
  5. It took me about 6 hours to find out why my custom thumbnails were not created after uploading an image. When I looked in the uploads folder on my server, only the original file was added. This error occurs when you have GD library missing. If you are on ubuntu and using php-fpm, then you just instaRead more

    It took me about 6 hours to find out why my custom thumbnails were not created after uploading an image. When I looked in the uploads folder on my server, only the original file was added.

    This error occurs when you have GD library missing.

    If you are on ubuntu and using php-fpm, then you just install php-gd library.

    In my case i ran

    apt-get install php8.0-gd

    Do not forget to restart the php-fpm

     

    See less
  6. This code from http://php.net/unlink: /** * Delete a file or recursively delete a directory * * @param string $str Path to file or directory */ function recursiveDelete($str) { if (is_file($str)) { return @unlink($str); } elseif (is_dir($str)) { $scan = glob(rtrim($str,'/').'/*'); foreach($scan as $Read more

    This code from http://php.net/unlink:

    /**
     * Delete a file or recursively delete a directory
     *
     * @param string $str Path to file or directory
     */
    function recursiveDelete($str) {
        if (is_file($str)) {
            return @unlink($str);
        }
        elseif (is_dir($str)) {
            $scan = glob(rtrim($str,'/').'/*');
            foreach($scan as $index=>$path) {
                recursiveDelete($path);
            }
            return @rmdir($str);
        }
    }
    See less
  7. If you want to delete everything from folder (including subfolders) use this combination of array_map, unlink and glob: array_map( 'unlink', array_filter((array) glob("path/to/temp/*") ) );

    If you want to delete everything from folder (including subfolders) use this combination of array_map, unlink and glob:

    array_map( ‘unlink’, array_filter((array) glob(“path/to/temp/*”) ) );

    See less
  8. The friend keyword in C++ allows the programmer to declare friend functions and classes. class frnd{ private: void somefunc(); }; int frndFUNC(int a) {} class A{ friend class frnd; friend int frndFUNC(int a); }; Some important points about friend functions and classes: Declarations of friend functioRead more

    The friend keyword in C++ allows the programmer to declare friend functions and classes.

    class frnd{
    	private:
    		void somefunc();
    };
    
    int frndFUNC(int a) {}
    
    class A{
    	friend class frnd;
    	friend int frndFUNC(int a);
    };
    
    
    

    Some important points about friend functions and classes:

    1. Declarations of friend functions and classes are always made inside the class definition(can be anywhere either in public and private)
    2. Friend functions and classes are declared by the implementor i.e. only the class can define its friend functions and classes, a function or class cannot declare itself a friend of a class
    3. Friend classes can access the data members of the class but not vice versa i.e. Class frnd can access the data members of class A but class A cannot access members of class frnd.
    4. Friend functions are not inherited.
    See less
  9. The correct answer is b) Returns a string with HTML response

    The correct answer is b) Returns a string with HTML response

    See less
  10. Because your <a> tag is being displayed as block or inline-block.

    Because your <a> tag is being displayed as block or inline-block.

    See less