The Complete JavaScript Guide - Functions
@ajaythopate

The Complete JavaScript Guide - Functions

Functions are one of the fundamental building blocks in JavaScript.

  • With functions you can reuse code
  • You can write code that can be used many times.
  • You can use the same code with different arguments, to produce different results.

The basic syntax to create a function in JavaScript

function functionName(parameter1 , paramater2){

      //  function body

}        

Function Declarations

  • Every function should begin with the keyword function followed by,
  • A user-defined function name that should be unique,
  • A list of parameters enclosed within parentheses and separated by commas,
  • A list of statements composing the body of the function enclosed within curly braces {}.


Basic declaration of a function in javascript

function calAddition(num1 , num2){

   return num1 + num2;
}
console.log(calAddition(6,4));


// output --- > 10        


Function Expression

  • Function expressions can be stored in a variable assignment.?

Code for Function Expression

let calSub = function (x, y) {
	let z = x - y;
	return z;
}

console.log("Subtraction : " + calSub(7, 4));



// output ----> 3        


Arrow Function

  • It is one of the most used and efficient methods to create a function in JavaScript

const name = () => { 
	console.log( "Hi I am Ajay!" ); 
} 

name();
        


Function Parameters

  • The parameters are passed to the function within parentheses after the function name and separated by commas.
  • A function in JavaScript can have any number of parameters and also at the same time
  • a function in JavaScript can not have a single parameter.

function multiply(a, b) {
	b = typeof b !== "undefined" ? b : 1;
	return a * b;
}

console.log(multiply(69)); 


//output---->  69
        

要查看或添加评论,请登录

Ajay Thopate的更多文章

  • RIP

    RIP

    Routing Information Protocol. RIP is open standard protocol.

    2 条评论
  • ROUTING PARAMETERS

    ROUTING PARAMETERS

    Metric :- It is the parameter used by the routing protocol to find it’s best path RIP – Hop count (distance) OSPF –…

  • STATIC ROUTING

    STATIC ROUTING

    Static routing is the manual method of routing. Static routes the administrative distance is as default value.

  • ROUTING

    ROUTING

    A router is a network device that connects computing devices and network to other network. Routing is the process of…

  • Collision domain and Broadcast domain

    Collision domain and Broadcast domain

    Collision Domain Collision Domain is a single physical line that a collision can occur. If one more device tries send…

  • IP Address

    IP Address

    An Internet Protocol (IP) address is the unique identifying number assigned to every device connected to the internet…

  • TCP/IP – Model

    TCP/IP – Model

    TCP – Transmission Control Protocol. IP – Internet Protocol.

  • OSI Model

    OSI Model

    OSI - Open System Interconnection. OSI model created in 1984 by ISO.

    1 条评论
  • INTRODUCTION AND BASIC INFORMATION OF NETWORK DEVICES

    INTRODUCTION AND BASIC INFORMATION OF NETWORK DEVICES

    Types of Network Devices :- 1. Hub 2.

  • The Complete JavaScript Guide - Scope

    The Complete JavaScript Guide - Scope

    In JavaScript, there are two types of variable scopes: Global Scope : Variables declared Globally (outside of any…

社区洞察

其他会员也浏览了