Back to articles
Functions
NewsTools

Functions

via Dev.toNanthini Ammu

Function : Reusable blocks of code designed to perform specific tasks Function run when it is called. Example : function greet () { console . log ( " Hello! " ); } greet (); Output : Hello ! Functions with Parameters : Parameters allow to pass values to a function. Parameters are listed inside the parentheses in the function definition. Parameter : Variable in function definition Argument : Actual value passed to function function add ( a , b ) { // 'a,b' is Parameter console . log ( a + b ); } add ( 5 , 6 ); // "5,6" is Argument function greet ( name ) { console . log ( " Hello " + name ); } greet ( " Varun " ); Output : Hello Varun Return Values : A function can return a value back to the code that called it. When a function reaches a return statement, the function stops executing.The value after the return keyword is sent back to the caller. function add ( a , b ) { return a + b ; } let result = add ( 5 , 3 ); console . log ( result ); Outpu : 8 Function Types Function Declaration.

Continue reading on Dev.to

Opens in a new tab

Read Full Article
2 views

Related Articles