JavaScript for beginners - Chapter 21 - Function (Methods) in JavaScript

preview_player
Показать описание
Javascript Function(Method)
Function in JavaScript.
A function is a block of reusable code.
Advantage of using a function :
A function allow us to write code once and use it many times as we want just by calling the function.
JavaScript function syntax :
function functionName(parameter1, parameter2,...parameter_n)
{
//function statements
}

Use the function keyword to define a function, followed by the name of the function .
The name of the function should be followed by parentheses.
Function parameters are optional.
Example : Function to add two numbers

function mutliplyNumbers(firstNumber, secondNumber)
{
var result = firstNumber * secondNumber;
return result;
}

Calling the JavaScript function :
Call the JavaScript function by specifying the name of the function and values for the parameters if any.

function mutliplyNumbers(firstNumber, secondNumber)
{
var result = firstNumber * secondNumber;
return result;
}

var multiply = mutliplyNumbers(5, 5);

The parameters that are missing values are set to undefined.
When we specify too many parameter values to the calling function, the extra parameter values will be ignored.
It’s not compulsory, that JavaScript function should always return a value. It totally depends on what you want the function to do.
If an explicit return is omitted, undefined is returned automatically.

ankpro
ankpro training
C#
C sharp
Bangalore
Rajajinagar
Selenium
Coded UI
Mobile automation testing
Mobile testing
JQuery
JavaScript
.Net
Components of the .Net framework
Hello World
Literal
Keywords
Variable
Data types
Operators
Branching
Loops
Arrays
ArrayList
Strings
String Builder
Structures
Enums
Functions
Classes
Inheritance
Polymorphism
Properties
Indexers
Events
Nested Classes
Delegates
Anonymous methods
Labda expressions
Abstract classes
Exception Handling
Linq
Interfaces
Extension methods
Anonymous types
Generics
Collections
Garbage Collection
Reflection
Attributes
Input and output statements
Type casting
Partial Methods
Partial Classes
Boxing and Unboxing
Var vs Dynamic vs Object
using Static.
Auto property initializer.
Dictionary Initializer.
nameof Expression.
New way for Exception filters.
await in catch and finally block.
Null – Conditional Operator.
Expression – Bodied Methods
Easily format strings – String interpolation
Parameterless constructors in structs.
Creating a custom exceptions class.
Рекомендации по теме