Skip to content

promahbubul/JavaScript_Note_4_Function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

JavaScript Function

Function

function() {}

function greatWorls() {
  console.log("Hello world");
}
greatWorls();

Exercise

function getReminder() {
  console.log("Water the palnet");
}
getReminder();
function getInSpanish() {
  console.log("Buenas Tardes");
}
getInSpanish();
Parameters and Arguments
calculateArea(20, 10);

function calculateArea(width, height) {
  console.log(width * height);
}
    

Exrecise

sayThanks("Ashraf");
sayThanks("Siddik");
sayThanks("Jahangir");
sayThanks("Alam");

function sayThanks(name) {
  console.log("Thank you for your parchase " + name + "! We appreciate your business." );
}
Default Parameters
function animal(name = "Tiger") {
  console.log(`Animal is ${name}`);
  }

  animal("Cow"); // Outpur: Animal  is Tiger
  animal();  // Output: Animal is Tiger

Exercise

makeShoppingList();
function makeShoppingList(item1="Milk", item2="Bread", item3="Eggs") {
  console.log(`List: ${item1}, ${item2}, ${item3}`) 
}
makeShoppingList("Rice", "Alo", "Potato");
function makeShoppingList(item1="Milk", item2="Bread", item3="Eggs") {
  console.log(`List: ${item1}, ${item2}, ${item3}`) 
}
Return

without return

function rectangleArea(width, hight) {
      let area = width * hight
    }
    console.log(rectangleArea(5, 7)) // Prints: Undefined

with return

 function rectangleArea(width, hight) {
      let area = width * hight;
      return area;
      console.log("hello");
    }
    console.log(rectangleArea(5, 7));

Exercise

 const numOfMonitors = monitorCount(5, 4);
    console.log(numOfMonitors);

    function monitorCount(rows, columns) {
      return rows * columns;
    }
Helper Function
Function Expressions
const plantNeedsWater = function(day) {
        if(day === 'wednesday') {
          return true;
        } else {
          return false
        }
      }
      
      console.log(plantNeedsWater("Thuesday"));
      console.log(plantNeedsWater("wednesday"));
Arrow Expressions
const plantNeedsWater = (day) => {
  if(day === 'wednesday') {
    return true;
  } else {
    return false
  }
}

console.log(plantNeedsWater("Thuesday"));
console.log(plantNeedsWater("wednesday"));
Concise Body Arrow Funciton
const plantNeedsWater = (day) => day === 'wednesday'
      console.log(plantNeedsWater("Thuesday"));
      console.log(plantNeedsWater("wednesday"));

About

JavaScript Note Function

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages