Web制作

JavaScript functions/anonymous functions/arrow functions ~ Programming learning [Friday]

A function is a collection of processes defined when you do not want to repeat the same process over and over again.

We created a function to avoid repetitive processing, so when we want to perform that process, we just call the function and have it perform the process.

To call it, simply specify the function name, such as function name ( );.

This completes the function processing.

In programming, systems like this are implemented as languages.

A function can be defined with two arguments.

The arguments here are x and y.

function add(x,y){
  const sum=x+y;
  return sum;
}

const result=add(3,4);
console.log(result);

When calling a function, you can imagine passing a specific number like 3 or 4 and calling a predefined function.

Arguments when calling a function can be referred to as "actual arguments" in relation to their specificity.

On the other hand, the arguments when defining a function, in this case x and y, are "formal parameters."

Next, we will modify the way the function is written little by little.

First, the basic system.

function findTriangleArea(a,b){
  return a*b/2;
}

const area=findTriangleArea(5,2);
console.log(area);

Next is the anonymous function.

Originally, as shown earlier, the function name findTriangleArea was defined after function, but that was removed and the anonymous function was assigned to the variable findTriangleArea.

const findTriangleArea=function(a,b){
  return a*b/2;
}

const area=findTraiangleArea(5,2);
console.log(area);

Next, write using arrow functions.

Assign the arrow function to the findTriangleArea variable.

const findTriangleArea=(a,b)=>a*b/2

const area=findTriangleArea(5,2);
console.log(area);

You can make it this short.

【Friday】

In a work setting, having to communicate or do the same thing over and over again, and having to be interrupted midway through, is a big burden even when you consider the time loss.

Even if you just change your location and don't check your email, you'll feel like your work progresses faster in the future.

If you look around at the people busily doing the same thing over and over again, you may find that they are actually just doing the work they are used to doing.

I think it's not uncommon for people in a group to reject new things or react in a restraining manner, but this seems to be due to a psychological state where they don't want to escape from their comfort zone.

In programming, you can easily handle the same thing by preparing a function, so I think it's useful to be able to understand the logic.

Japanese programming school/Attendance/Reference

-Web制作

Copyright© サァーチpage , 2024 All Rights Reserved.