
Functions in javascript
JavaScript FUNCTION?
*A JavaScript function is a block of code.
*A JavaScript function is executed when “something” invokes it.
SYNTAX ….⬇️
A function is defined with the function keyword, followed by a name, followed by parentheses ().
The code to be executed, by the function, is placed inside curly brackets: {}

TRY THIS:
function function_name()
{
console.log("hello world!");
}
function_name();

TRY THIS:
function greeting()
{
return `Hello ${user} !`;
}
let user = “bk_bharathikannan”;
let string =greeting();
console.log(string);
OR
function greeting()
{
return "Hello " + user+"!!";
}
let user = "bk_bharathikannan"
let string =greeting();
console.log(string);
Function parameters & Function arguments…⬇️
Function parameters are the names of variables present in the function definition. Function arguments are the real values that are passed to the function and received by them.

TRY THIS:
function greeting(user)
{
return "Hello "+ user + "!!";
}
let string =greeting(“bk_bharathikannan”);
console.log(string);
FUNCTION EXPRESSION⬇️

Anonymous Function⬇️
Anonymous Function is a function that does not have any name. Normally we use the function keyword before the function name to define a function in JavaScript.But, whenever we use anonymous functions in JavaScript, we use only the function keyword without the function name.

TRY THIS:
let anonymous_function = function(num1 ,num2)
{
return num1 * num2;
}
anonymous_function(5,5);
OR
let anonymous_function = function(num1 ,num2)
{
return num1 * num2;
}
let result =anonymous_function(5,5);
console.log(result);
let anonymous_function = function(num1 ,num2)
{
return num1 * num2;
}
let sum =anonymous_function;
let result =sum(5,5);
console.log(result);
Local — variable(function)⬇️
* They can only be accessed from within the function.
let str = "bk_bharathikannan";
function string()
{
console.log("THE STRING IS " +str);
}
string();
Global — variable(function)⬇️
A variable declared outside a function, Becomes GLOBAL……
function string()
{
let name ="bk";
}
console.log(name);
string();
ARROW FUNCTION:-⬇️
* Arrow functions were introduced in ES6.
* Arrow functions allow us to write shorter function syntax:
let myFunction = (a, b) => a * b;
let myFunction = (a, b) => a * b;
myFunction(10,10);

HOISTING :-⬇️
In JavaScript, a variable can be declared after it has been used is known as Hoisting…..

ADVANCE CONCEPT IN FUNCTIONS
JavaScript has several advanced concepts and functions that can be used to write more powerful and efficient code. Some examples include:
Closures:
A closure is a function that remembers the variables in the scope in which it was created. This allows the function to access those variables even after the scope has closed.
Higher-Order Functions:
A higher-order function is a function that takes another function as an argument or returns a function as a result. This allows for powerful functional programming techniques, such as map, filter, and reduce.
Promises:
Promises are a way to handle asynchronous code in JavaScript. They allow you to write code that will execute only after a certain event has occurred, such as a network request completing.
Async/Await:
Async/await is a way of working with promises in JavaScript that makes the code more readable and easier to understand.
ES6 Classes:
ES6 Classes are a way to create objects with the same properties and methods. It is a simpler and more powerful way of working with object-oriented programming in JavaScript.
Generators:
Generators are special functions that can be paused and resumed, allowing you to control the flow of your code and work with large data sets.
Destructuring:
Destructuring is a way to extract values from arrays and objects, making it easier to work with complex data structures in JavaScript.
Spread and Rest Operators:
Spread and Rest operators are used to spread and gather the elements of an array or object.
These are just some examples of advanced concepts and functions in JavaScript, there are many more powerful tools to use and improve your code............
THINK TWICE💭-code once!
THANKS_FOR_READING_!🌟
❤️“Have a Fine_Day”❤️
About the Creator
bk_bharathikannan
YOUNG FRONTEND DEVELOPER



Comments
There are no comments for this story
Be the first to respond and start the conversation.