7.Arrow Functions in Javascript - Passing Objects to Functions - Passing Array to Functions

Sharing buttons:

now moving on to the next topic that is

going to be our arrow functions now

water arrow functions let hear it

properly arrow functions are an

alternative way of writing a function

right if you heard me properly an arrow

function it's an alternative way of

writing a function how do you write a

function we will take a function name we

will take a function keyboard we will

take the function name add anything

it will take some parameters if are if

there are any parameters you will open

and close the parentheses then you have

your return statement if it is there

return something you will have return

something so this is the syntax of our

normal function traditional function but

usually we don't use these functions in

JavaScript remember this thing so what

are the advantages of using io functions

our function is going to emit the

function given first advantage is going

to omit the curly braces if there is

only one expression third it is going to

omit the parentheses if there is only

one argument let us see that practically

for example if I have a statement which

says return a plus B it takes two

argument a comma B so how do I convert

this first remove that function keyword

take a variable taken in a part take

that ad here is equal to remove that

function keyword now what you gonna do

is you can take how many parameters are

the two parameters for two parameters

you have to take the parentheses for no

parameters you have to take the

parentheses for single parameters you

have you need not to take that there are

cases so for now I will take the

parentheses that's going to be a plus B

that's it arrow operator is equal to and

greater than sign combination then your

return statement a plus B so this is

your arrow function C you can see how

simplified it became now very very

simple it became now okay so I'll just

commend this thing I'll comment on

traditional function this is our arrow

function what I will do I will give add

1 comma 2

console dot log off so I should get

three without any errors okay

save the function refresh the page

you got three year so that shows all

about arrow function let me show you how

we will work with null parameters for an

alpha rameters just don't give anything

you don't you will not have anything you

now what you will do is you know since

there are no parameters you will not

pass the parameters you do something

here as a console dot log called

called so let me call this function now

just add ad you have to take the curly

parenthesis here and save it refresh and

you got called okay next the last thing

what if I have only one parameter over

you'll do is for example for your


I'm writing a traditional function

traditional function and I'm going to

just give one parameter here a I'll

return a by two okay

this is a traditional function now take

var function name is equal to parameter

named arrow function curly braces a bite

to return statement understood locked a

at function with the 10 so I'm expecting

the answer five here and selling can so

short log log of a right to now that's

what I'm gonna do here refresh and give

God five year now the next topic is

going to be your district setting

assignments so what we will do here now

we have seen certain topics now

we have seen how to create a function

how to pass parameters to a function how

to take return values from a function

and we have seen also how to refer to a

function okay so we have seen those

things now what we're gonna do is we

will try to pass instead of variables we

will try to pass an object through the

function so what is it object I have

already discussed that in my first video

you can go in the description and watch

that video

till this duration I have spoken about

the objects now what we will do is we

will create an object and we will pass

the values of object to a function of

the object and of the object and it will

do the work that we are going to tell it

to do it tell it to do for example I'll

create a I will create an object of

student is equal to student will have

his name I'll take some name as odd coma

I will take age may be 21 now I will

take as branch that is going to be C 3 s

C so I will put a semicolon here so I've

created a new object so how do I access

that wrong and axis is student dot H

this was the thing we have seen in the

first video first

now what I am going to do is I will

create a function sorry I will create a

function that will print object now you

have to be careful here between the

parenthesis you have to take curly

braces with the names of the attributes

of your objects for now I'll take name

name comma age comma branch so that's

how you're gonna do with the syntax it

now let us move here into the function

what we will do with this print we will

just print sing your name is this your

name is this age is this and like that

console dot log your name is

Plus name next I'll copy this console

paste paste so your age is age and your

branch is rat so we have past we have

created a function that will - will take

an object as its parameter so let us

call the function that's where the

function is going to work now

name of the function print obj then I

will take the name of the object that is

sorry then I will take the name of the

object that is student okay so what it

is gonna do if I run the script file we

will see on the console your name is

dawn age 21 branch is CSC let me save

this file and open the HTML file third

now here you cannot you cannot say

anything what if I go in the console

here okay you can see in the console

your name is John your age is 21 your

branch is CSE so I've successfully

passed or when it's passing we will pass

the object to a function now let us do a

similar topic that is passing an array

to a function so if you don't know what

is an array it is just a collection of

elements similar data types the main

difference is the data type in the error

should be similar you cannot take one

two and some name string everything

should be a number if you want number

array if you want some names

everything should be a string for

example I'm creating an array of num

that is going to have some one two three

numbers next I will create a function

that will print num in this you have to

use square bracket previously we have

used curly braces take how many values

are there three values take three

variables next console dot log just

printing those values nothing much so

calling the

function print num with the name of the

array save this file I'm going to

refresh the browser and see my console I

have got one two three so this is what

we are going to pass a four array to a

function basically so this was all about