Skip to main content

Aha..!! That's JavaScript

Aha..!!  That's JavaScript

 kind of mixed feelings, I'll post  - JavaScript, TypeScript, vue.js, react, angular.

 This might help in Interviews as well.


TYPE of 

typeof null          // "object" (not "null" for legacy reasons)

typeof undefined     // "undefined"

null === undefined   // false

null  == undefined   // true

null === null        // true

null  == null        // true

!null                // true

isNaN(1 + null)      // false

isNaN(1 + undefined) // true

typeof(NaN)     // number


FAT Arrow function - ES6

Syntax difference 

// Regular Function Syntax ES5:var add = function(x, y) { return x + y;};// Arrow function ES6let add = (x, y) => { return x + y };

Arguments binding

// Object with Regular function.

let getData = {

// Regular function

    showArg:function(){

      console.log(arguments);

    }  

}

getData.showArg(1,2,3); // output {0:1,1:2,2:3}

------------------------------------------------------------------

// Object with Arrow function.

let getData = {

// Arrow function

    showArg:()=>console.log(arguments)

}

getData.showArg(1,2,3); // Uncaught ReferenceError: arguments is not defined

Use of this keyword

let name ={
fullName:'Vandna Kapoor',
printInRegular: function(){
console.log(`My Name is ${this.fullName}`);
},
printInArrow:()=>console.log(`My Name is ${this.fullName}`)
}
name.printInRegular();
name.printInArrow();

Using a new keyword

let add = (x, y) => console.log(x + y);

new add(2,3);

No duplicate named parameters

Arrow functions can never have duplicate named parameters, whether in strict or non-strict mode.

However, We can use duplicate named parameters for regular function in non-strict mode.

found this on YouTube: link ref below

1. Use TS + tRPC to ensure you have type safety. 

2. Use AbortSignal to invalidate previous requests when a new character is input.

tRPC - Move Fast and Break Nothing. End-to-end typesafe APIs made easy. | tRPC

AbortSignal - Web APIs | MDN (mozilla.org)

 avoid debouncing: it's a programming pattern or a technique to restrict the calling of a time-consuming function frequently, by delaying the execution of the function until a specified time to avoid unnecessary CPU cycles and API calls and improve performance.

             It's a higher-order function that returns another function, to create closure around the function params (foo, timeout) and the timer intervals.


CSS stuffs too:

LESS  SASS SCSS MIXINS --- source geeksforgeeks

LESS stands for Leaner Style Sheets. It is a backward-compatible language extension for CSS. It allows us to use features like variables, nesting, mixins, etc, all in a CSS-compatible syntax. LESS is influenced by SASS and has influenced the newer “SCSS” syntax of SASS. LESS was used in Bootstrap 3 but was replaced by SASS in Bootstrap 4. 

File Type: All LESS files must have the .less file extension.

Working: A web browser does not understand the LESS code itself. That is why you will require a LESS pre-processor to change LESS codes into simple standard CSS code.

Working Steps:

  • Write the LESS code in a file.
  • Compile the LESS code into CSS code using the command lessc style.less style.css.
  • Include the compiled CSS file in the html file.

Features:

  • Variables: Variables can be used to store CSS values that may be reused. They are initialized with @
@lt-gray: #ddd;
@background-dark: #512DA8;
@carousel-item-height: 300px;
h1 {
    color:@lt-gray;
    background:@background-dark;
}

To compile the above less code to CSS code write the following command-

lessc style.less style.css
h1 {
  color: #ddd;
  background: #512DA8;
}

  • Mixins: Mixins are a way of including a bunch of properties from one rule-set into another rule set. 
zero-margin {
    margin:0px auto;
    background: white;
}
 
.row-header {
    margin:zero-margin;
    padding:0px auto;
}
 
.row-content {
    margin:zero-margin;
    border-bottom: 1px ridge;
    min-height:400px;
    padding: 50px 0px 50px 0px;
}

To compile the above less code to CSS code write the following command-

lessc style.less style.css
compiled below:
zero-margin {
  margin: 0px auto;
  background: white;
}
.row-header {
  margin: zero-margin;
  padding: 0px auto;
}
.row-content {
  margin: zero-margin;
  border-bottom: 1px ridge;
  min-height: 400px;
  padding: 50px 0px 50px 0px;
}

  • Nesting: LESS gives you the ability to use nesting
@lt-gray: #ddd;
@background-dark: #512DA8;
@carousel-item-height: 300px;
.carousel {
    background:@background-dark;
 
    .carousel-item {
        height: @carousel-item-height;
        img {
            position: absolute;
            top: 0;
            left: 0;
            min-height: 300px;
        }
    }
}

To compile the above less code to CSS code write the following command-

lessc style.less style.css

The compiled CSS file comes to be: 

style.css

CSS

.carousel {

  background: #512DA8;

}

.carousel .carousel-item {

  height: 300px;

}

.carousel .carousel-item img {

  position: absolute;

  top: 0;

  left: 0;

  min-height: 300px;

}

Mathematical Operations: Arithmetical operations +, -, *, / can operate on any number, color, or variable. 

style.less


CSS


@lt-gray: #ddd;

@background-dark: #512DA8;

@carousel-item-height: 300px;

 

.carousel-item {

    height: @carousel-item-height;

}

 

.carousel-item .item-large {

    height: @carousel-item-height *2;

}

Syntax: To compile the above less code to CSS code write the following command-


lessc style.less style.css

The compiled CSS file comes to be: 


style.css


CSS




.carousel-item {

  height: 300px;

}

.carousel-item .item-large {

  height: 600px;

}

Functions: LESS provides a variety of functions like math, list, string, color operations, color blending, etc. 

style.less


CSS


@base:0.5;

@width: 0.8;

 

.class {

    width: percentage(@width); // Returns `80%`

    color: saturate(@base, 5%);

    background-color: light(@base, 25%), 8;

}

Syntax: To compile the above less code to CSS code write the following command-


lessc style.less style.css


The compiled CSS file comes to be: 


.class {

  width: 80%;

  color: saturate(0.5, 5%);

  background-color: light(0.5, 25%), 8;

}


------------------------------------------------

some concepts: 

  1. var, let, const
  2. conditionals
  3. debugging
  4. classes and objects
  5. inheritance 
  6. private, protected, getter/setter functions
  7. error handling - try/catch, extending errors, validations, exception
  8. promise, callbacks, promise chaining, microtasks, Async/await
  9. generators, async iteration and generators
  10. modules, import, export, defer, dynamic imports 
  11. proxy, reflect, currying, string intervals
  12. DOM querySelectors, styles, window sizing, scrolling, browser events, custom events
  13. event bubbling, capturing, animations, mouse/pointer events, keyboard
  14. fetch api, form, polling, XHR, URL objects, cross-origin reqs, websocket, server events
  15. cookies, local and session storage
-----------------------

JavaScript Hoisting: 
 

Comments

Popular posts from this blog

GraphQL vs REST

  GraphQL   GraphQL is an application layer server-side technology which is developed by Facebook for executing queries with existing data. GraphQL can optimize RESTful API calls. It gives a declarative way of fetching and updating your data. GraphQL helps you to load data from server to client. It enables programmers to choose the types of requests they want to make. REST REST is a software architectural style that defines a set of constraints for creating web services. It is designed specifically for working with media components, files, or hardware device. The full form of REST is Representational State Transfer. ========================================================= Here is the important difference between GraphQL and REST. GraphQL REST GraphQL is an application layer server-side technology which is developed by Facebook for executing queries with existing data. REST is a software architectural style that defines a set of constraints for creating Web services. It follow...

DBMS ACID Properties

 1. Atomicity states that database modifications must follow an all or nothing rule 2. Consistency states that only valid data will be written to the database. If, for some reason, a transaction is executed that violates the database's consistency rules, the entire transaction will be rolled back and the database will be restored to a state consistent with those rules.  3. Isolation requires that multiple transactions occurring at the same time not impact each other's execution. For example, if Joe issues a transaction against a database at the same time that Mary issues a different transaction, both transactions should operate on the database in an isolated manner. The database should either perform Joe's entire transaction before executing Mary's or vice-versa. 4.  Durability ensures that any transaction committed to the database will not be lost. Durability is ensured through the use of database backups and transaction logs that facilitate the restoration of committe...

Git Commands

  Git commands sorted. Reference: https://git-scm.com/docs Git task Notes Git commands Tell Git who you are Configure the author name and email address to be used with your commits. Note that Git strips some characters (for example trailing periods) from user.name . git config --global user.name "Sam Smith" git config --global user.email sam@example.com Create a new local repository   git init Check out a repository Create a working copy of a local repository: git clone /path/to/repository For a remote server, use: git clone username@host:/path/to/repository Add files Add one or more files to staging (index): git add <filename> git add * Commit Commit changes to head (but not yet to the remote repository): git commit -m "Commit message" Commit any files you've added with git add , and also commit any files you've changed since then: git commit -a Push Send changes to the master branch of your remote repository: git push origin master Status List the...