Coder Social home page Coder Social logo

js-basics's Introduction

JS-Basics

ARROW FUNCTION

//regular function call
function add(a)
{ 
  a="supraja";
  return a+"arthi"; 
 }
 // Remove function kewyord 
 add = (a) =>
 { 
 a="supraja";
 return a+"arthi";
 }
 // Remove {} curly braces and parse parameter within () paranthesis
 add=(a="supraja") => a+"arthi";

EVENT HANDLER

  • const variable = document.querySelector(".classname");

  • window.getComputedStyle(variable);

  • It gives the color, font family and everything in the tag / class

OBJECTS

var user = {
name:"",
getUserName:function()
	console.log(`User name is ${this.name}`);
}
// Create obj using "create" keyword
var cat = Object.create(user);
cat.name="cat";
// Create obj using "new" keyword
var bat = new user("bat");
  • obj {prop:value}
  • obj has
    • constructor
    • prototype
  • Assume the following scenario :
  • every time the user signs into a page
  • he is assigned certain properties
  • props like fname,lname,..
  • note that username should be unique
  • each time a new instance of object is created

NEW KEYWORD

  • new kw makes use of the entire syntax
  • It invokes the custom constructor and creating a unique instance every single time
  • new creates a new copy of the entire obj
  • It creates unique instances and objects through the obj call
    • We saw that whenever there is a regular func call it refers to a window obj ,
    • w/o using new keyword it gives undefined
    • bcoz w/o "new" it refers to window obj which is {} empty obj so it gives undefined
    • seperate instances of users are created

THIS KEYWORD

  • this keyword either contains window object / whatever the global obj is
    • in node global obj is {} empty obj
    • or the object we have predefined
  • All regular function calls are window objects
  • If it is an obj call rather than func call, this kw points to the object

PROTOTYPES

Prototyes can inject your own stuff by

  • access or give properties
  • give functions
  • getters
  • setters
  • methods
  • can act as constructors to override the properties
    • It runs outside of the object
    • And accesses the properties of the function
  • Prototype has its properties like
    • fill,filter
    • hasOwnProperty

SELF EXECUTING ANONYMOUS FUNCTIONS

  • Does not have a name
  • Cannot be called
  • Syntax
(function(){
console.log("Say Hello");
})();

FUNCTIONAL PROGRAMMING

  • Instead of being declared in global variable , values are passed in parameters
  • Instead of reusing the same variables, new variables are being used
  • Functions can be used in parameters and return values

LEXICAL SCOPING

function init() {
	var firstName = "SuprajCat";
	function sayfirstName(argument) {
		console.log(firstName);
	}
	sayfirstName();
}
init();
}
  • init() is called in top of the global executional context
  • sayFirstName() on top of init executional context, another context is going to mount up
  • init() gets executed 1st , then nested funcs get executed one by one

CLOSURE

  • Here init just returns the sayfirstName func
  • So the init context is not cleared , it gets stacked
  • So assigning it to a variable and calling it gives the o/p
  • The parameter can be passed as follows (x:=>any)(y:=>any) due to closure
console.log(addition(7)(7));

js-basics's People

Contributors

suprajaarthi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.