DEV Community

Akash
Akash

Posted on

Constructor Function ,Methods in JS

  • Constructor function is usually started with capital letter
  • It used with new keyword
  • It helps to create object without repeating code

(e.g)
function Bike(model,price,colour)
{
this.model=model;
this.price=price;
this.colour=colour;
console.log(this.bike1.colour);
console.log(this.bike2.model);

}
const bike1=new bike("RX 100",100000,"black");
const bike2=new bike("Royal Enfield",200000,"grey");

OUTPUT:Black
Royal Enfield

EXPLANATION:

  1. Declaring function() bike
  2. In construction function this is used as a keyword for identifying specific value
  3. Declaring values for function
  4. print a needed variable using this (this is used for indicating particular function)

ARRAY SPECIFICATIONS

  • Array includes
  • Elements
  • Objects
  • Zero Indexed
  • Dynamic size
  • Ordered

METHODS IN ARRAY(TBD)

  • Array push * Array flat
  • Array length * Array slice
  • Array shift * Array splice
  • Array unshift * Array join
  • Array delete
  • Array concat

RETURN STATEMENT

  • By returning value to function we can use the same value in multiple function
  • we can use a return statement in anytime
  • usefull for looping

(e.g)

function multiply(a,b)
{
return a*b;
}
let sum = multiply(10,7);
console.log(sum)

OUTPUT: 70

Top comments (0)