Javascript Define and Call Functions

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/javascript-define-call-functions/
PINTEREST
PINTEREST
INSTAGRAM

Up to now we have write out code line by line. But there is problem with that. What will we do if the same 3 line code should be used in different 120 places. Here functions come to play. Functions a block of code that can be used just with single line.

  • function  is the keyword used to specify function
  • sum is the name of the function and will be used to call function
  • (a,b) specifies parameters of the function. Parameter is input value for functions.
  • return is keyword used to give back new value to the function callers. s1,s2,s3 is assigned to the values calculated by function.
  • s1 is assigned value which is calculated by sum function with values 1,2 . s1 will hold sum of 1 and 2 which is 3

Function do not have to return a value. So following function is valid too

  • slogan function do not have any parameters because it do not need. Also this function do not return a value just prints to console
RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/javascript-define-call-functions/
PINTEREST
PINTEREST
INSTAGRAM

LEARN MORE  Python Modules Tutorial With Examples

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)