Looking for the JavaScript Training? Join Infibee Technologies is one of the best JavaScript Course offering expert mentors with 10+ years o
seen from Netherlands

seen from United States
seen from Norway
seen from Vietnam
seen from United States
seen from Germany
seen from Ukraine
seen from Australia

seen from Germany
seen from China

seen from Malaysia
seen from Germany
seen from United States
seen from Germany
seen from Spain
seen from United States
seen from Spain
seen from United States
seen from Germany

seen from United States
Looking for the JavaScript Training? Join Infibee Technologies is one of the best JavaScript Course offering expert mentors with 10+ years o
JavaScript Training Institute in Delhi | TCA India
TCA India is the largest educational institution known as the JavaScript training institute in Delhi. JavaScript text-based programming language used both on the client-side and server-side helps to develop interactive web applications and it is supply objects to control a browser and JavaScript can be used with back-end frameworks like Node.js to power the mechanics behind a web page.
Types of Functions in JavaScript- A Very Easy Explanation
Web designing or UI Development
is one of the best industry to join if you love challenges and want to lead a happy life. This industry is one of the top highly paying industry for youth. JavaScript is the key language either you are a web designer or UI developer. So, knowledge of JavaScript matters when you want to make your career here.
A function is a group of reusable code which can be called anywhere in your program. It eliminates the need of writing the same code repeatedly. It helps in writing modular codes. Mainly JavaScript has 2 types of functions:
Built-in functions:
Already defined in the JavaScript language, we invoke them again and again. Examples
window.alert( ), document.write( ), parseInt( ) etc.
User-defined functions:
Custom functions defined by user. Below, we will see how to define our own user-defined functions.
1. Function Definition
Before we use a function, we need to define it.
Syntax
: function functioName(parameter-list)
{
statements
}
To define a function in JavaScript, use the
function keyword
, followed by a
unique function name
, a list of
parameters
(that can be empty), and a
statement
block surrounded by curly braces.
Example
: function sayHi()
{
Var x=10;
alert(x);
}
This example above does not have any parameters.
2. Calling a Function
To call a function specify the function name with parenthesis in front of it in the body section. Similarly, a function can be called inside another user defined function too.
Syntax
:
<script type="text/javascript">
function
functionName
( )
{
….code to execute…..
} </script>
<script type="text/javascript">
functionName()
; <script>
Example
:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function helloAlert( )
{
alert("Hello World!"); }
</script>
</head>
<body>
<script type="text/javascript">
helloAlert();
<script>
</body> </html>
In the above example we have defined a function “
helloAlert
()”, this function is later called in the body of the code and outputs a pop up that says “Hello world”;
3. Function with Parameters/Arguments
When you call a function, you can pass along some values to it, these values are called
parameters or arguments
. Parameters are the variables we specify when we define the function. When the function is later called somewhere else in the code, arguments are the values passed as parameters. We can specify multiple parameters, separated by commas (,). The parameters then serve as variables that can be used inside the function.
Syntax:
function functionName( parameter1 , parameter2 . . . parameter n)
{
some code to be executed
}
Example:
<script>
function Hello( user ) { alert( "Hello " + user +”!”); }
</script> <script> welcome( "Rav" ); </script>
In this example, we define a function named
Hello
( ) that takes in one parameter, named
user
. When the function is called, we pass the argument "
Rav
”. The function above when invoked will display the message box
"Hello Rav!"
on the webpage.
4. Functions with a return Value
Sometimes you want your function to return a value back to where the call was made. This can be done by using
return
statement. When using return statement, the function returns the specified value. Return is an optional statement.
Syntax
:
function returningFunc(parameter)
{
Result= …. Execute code…
return result;
}
Example:
<html>
<head>
<script type="text/javascript"> function concatStrings(first, last) { var full; full = first + last; return full; } function secondFunction() { var result; result = concatStrings (‘raveen’, ‘anand’); document.write(result ); } </script> </head> Try above example we defined a function that takes two parameters and concatenates them before returning the resultant in the calling program.
5. Nested Functions
JavaScript allows function definitions to be nested within other functions as well. Still there is a restriction that function definitions may not appear within loops or conditionals. These restrictions on function definitions apply only to function declarations with the function statement.
Scope of the nested function is limited to its parent function
The inner functions can access its parent variables but not otherwise.
Syntax:
function outerFunction()
{
var a, d, e;
function innerFunction()
{
var f;
}
innerFunction ();
}
OuterFunction();
Example:
function hypotenuse(a, b) { function square(x) {
return x*x; } return Math.sqrt(square(a) + square(b)); } hypotenuse(1,2); In the above example we are calculating the hypotenuse of 2 numbers. Formula for hypotenuse is , here we calculate the square of the numbers in a nested function “square” which tales a number as input and returns its square.
6.
Anonymous Functions
anonymous function is a function that is declared without any name. These functions can be assigned to variables when they are created, which gives the same capabilities as using a name within the function head. One common use for anonymous functions is as arguments to other functions.
Example:
var anon = function() { alert('I am anonymous'); } anon();
Differences between creating a named function and an anonymous function:
anonymous function
An anonymous function assigned to a variable only exists and can only be called after the program executes the assignment.
Can change the value of a variable and
Named functions
Named functions can be accessed anywhere in a program.
assign a different function to it at any point Not flexible-fixed name
Self-executing anonymous functions or IIFE
Another use for anonymous functions is as self-executing functions. A self-executing anonymous function is a function that executes as soon as it’s created. To turn a normal anonymous function into a self-executing function, you wrap the anonymous function in parentheses and add a set of parentheses and a semicolon after it.
The benefit of using self-executing anonymous functions is that the variables you create inside of them are destroyed when the function exits
In this way, you can avoid conflicts between variable names, and you avoid holding variables in memory after they’re no longer needed. var myVariable = "I live outside the function."; (function() {
var myVariable = "I live in this anonymous function"; document.write(myVariable); })();
document.write(myVariable);
In the example above, we have a variable myVariable declared globally. We have an anonymous self-executing function using the same variable name. The
output
of this is “
I live in this anonymous function. I live outside the function”
7. Functions as Closures in JavaScript
A closure is the local variable for a function, kept alive after the function has returned. It is a function having access to the parent scope, even after the parent function has closed. An inner function is defined within an outer function. When the outer function returns a reference to the inner function, the returned reference can still access the local data from the outer function.
function greetVisitor(phrase) {
var welcome = phrase + "Folks!"; // Local variable
var sayWelcome = function() {
alert(welcome);
} return sayWelcome;
} var personalGreeting = greetVisitor('Hi');
personalGreeting(); // alerts "Hi Folks!"
Conclusion is that functions in
JavaScript
are must to know as they are the building blocks in it for a web designer. There are many types of functions, you will understand their importance as you will use them in your JavaScript courses. You can learn it separately from any training center or you can join a complete course in web designing from a reputed web designing institute.
Source: https://admec-multimedia-institute.blogspot.in/2018/01/types-of-functions-in-javascript-very.html
Top JavaScript Training Center in Noida offered by AIM-IT with 7 years experience JavaScript expert. Best JavaScript training institute with 1-DAY-FREE-TRIAL CLASS 100% PLACEMENT. Join today now AIM-IT.
Best JavaScript Training Institute in Noida | AIM-IT
Kickstart JavaScript course and see how our approach to learning can change your life. Go beyond HTML and CSS and get an exclusive command over this programming language to build interactive and modern app and website.
jQuery vs. JavaScript: Which One is Better
In beginning many web developers were confused about the term jQuery and JavaScript. And they are aware to know what is actually difference between jQuery and JavaScript. But they may surprise to know that both are same. Generally jQuery is a set of JavaScript API, which is designed to simplify HTML document traversing, animation, event handling and Ajax interactions.
But according to our choice to be a professional developer you must have a solid command over Javascript. If you are not aware about using JavaScript for website development, check out Javascript MasterCourse. Once you aware about JavaScript Language, you might analyze that jQuery Master Course fulfill most of your requirements and it's requires less coding than conventional JavaScript may require.
Introduction of JavaScript
JavaScript is scripting language which is developed to use within web browser. It is widely used for interface interactions. Slides show and another interactive components can easily done using this language.
JavaScript also widely used in creating game development, web applications, server side programming etc. New standards in JavaScript forces all web browsers to implement JavaScript formally, which reduces developers time and frustration trying to debug code for a specific web browsing client.
jQuery Introduction:
In early days when jQuery was not developed, web developer created their own frameworks in JavScript. These frameworks allowed developers to work around some specific bugs without wasting of time. Later a group of developers created JavaScript libraries, which was open source and free of cost and generally called JavaScript libraries.
So jQuery is a library of JavaScript developed by John Resig. It is easy to use and extremely powerful in comparison to other JavaScript libraries.
Which one is better?
Developer spend lot of time debating whether jQuery or JavaScript is best???? But the truth is that there is no correct answer of this question.... Either can be selected for development point of view, because whatever effects we perform using JavaScript, that effects can achieve using jQuery.
Some web development projects require traditional JavaScript, however jQuery is sufficient for most web development projects. Although jQuery may be preferably a choice for experienced developer, but as a fresher web developer should still take the time to learn both JavaScript and jQuery.
One biggest difference between jQuery and JavaScript is that jQuery has been optimized to support variety of browsers automatically. But Unfortunately JavaScript still has some issues with cross-browser compatibility due to poor JavaScript implementation.
Example:
jQuery
$ (‘body’) .css (‘background’, ‘#ccc’);
JavaScript
Function changeBachground(color) {
document.body.style.background = color;
//or
document.bgColor = color;
}
window.onload= “changeBackground (‘red’)”;
A single line of code accomplishes same result in jQuery, what it take 4 lines of JavaScript code.
Source: http://admec-multimedia-institute.blogspot.in/2016/08/jquery-vs-javascript-which-one-is-better.html
Basics Concepts of JavaScript
Java script is a client side scripting language and it is standardize by ECMA. Its code is written between opening <script> and closing </script> tags. By using JavaScript we can create dynamic web page. JavaScript is embedded within HTML.
<script> tag has "type" attribute you must need to add in scripts tag like.
<script type="text/javascript">
There are three ways to write JavaScript code in your web page.
embedded
external
inline
In external way: there is src attribute like <script type="text/javascript" src="script.js(filepath)"> while in embedded we write JavaScript inside the html page enclosed in <script></script> tags.
Note: never use inline because you write this in html elements so very difficult to manage.
What are Client Side Languages?
Client side scripting languages are executed on any client machine instead of server so it doesn't take time to execute.
What are Server Side Languages?
Server-side scripting is used in web development which involves scripts on a web server which produces a response customized for each client's request to the website.
Variable
variable stores the value.
variable have some to define.
1. variable name can be letter, number, any symbols.
var = x; var = 'bhumi'
2. variable name can't start with numbers it must start with letter.
3. variable name is case sensitive. Var and var both are different name
in JavaScript.
var = X; var = x; (both are different)
4. reserved keywords can't be given as variable name.
like function, switch, return etc.
5. logical operator[=, +, -, /] cannot use in variable name.
var = bh+bh;
6. blank space is not allowed within variable name.
var = 1 23;
Datatypes
The latest ECMAScript standard defines seven data types:
There are six primitive types of datatype.
1. Boolean
it has two values true and false.
2. null
it has one value null.
var a = null;
alert(a);//null
alert(a+'bhumi');//nullbhumi (concatenation)
3. undefined
variable has not assigned any value its undefined.
var a;
alert(a);//undefined
alert(a+'bhumi');//undefinedbhumi (concatenation)
4. number
variable has assigned by any number.
var a = 2;
5. String
variable has assigned by any latter.
var a = 'bhumi';
6. Symbol
(new in ECMAScript 6). A data type whose instances are unique and immutable.
Popups in JavaScript
There are three types of pop ups.
1. alert()
it is used for pop up alert message has one button is 'ok'.
alert('welcome to my website');//message
2. confirm()
it is used for conformation it has two button 'ok' and 'cancel'
confirm('Are you 18+');//ok and concel (Boolean = 0/1 or false/true)
3. prompt()
it is used to get vales from user.
prompt( 'Enter your age plz');
Function in JavaScript
A JavaScript function is a block of code designed to perform a particular task. A JavaScript function is executed when it call.
Syntax:
function function name(para1, para2)
{
return();
}
Example:
<button onclick="main()">Click me</button>
function main(){
alert('hey');
}
Benefits of Function
You can reuse code: Define the code once, and use it many times.
You can use the same code many times with different arguments, to produce different results.
function main(greet){
alert(greet);
}
main('namaste');
main('hi');
main('hello');
nested function:
function contains other function call nested function. Such functions are very useful for abstraction and encapsulation.
var name = 'Bhumi';
function main(){
//local;
nested();
}
main();
function nested(){
alert(name);
}
nested();
Scope in JavaScript
Two types of scope in function.
1. local variable
local variable can be use within the function. you cant use it out side the function.
2. global variable:
global variable can use anywhere in the code.
Conditionals in JavaScript
if...else:
-> Use if to specify a block of code to be executed, if a specified condition is true
-> Use else to specify a block of code to be executed, if the same condition is false
-> Use else if to specify a new condition to test, if the first condition is false
switch :
it has many alternative code to execute.
switch(condition){
case ..
break;
}
ternary:
it has two values true and false
var getName = 45;
var result = (getName == 45)?'yes it is':'no it is not';
alert(result);
Loops in JavaScript
Loops are set of code which is used to repeat the condition of loop block. Loops returns the true or false values depend on the condition.
You can counter the loops by increments and decrements.
For Loop:
syntax:
for (statement 1; statement 2; statement 3) {
code block to be executed
}
for (var i = 0; i < 10; i++) {
console.log(i);//0,1,2,3,4,5,6,7,8,9
};
For in loop
When variable does not stored in array or variable have key pvalue pair then you can use for in loop.
Syntax:
for (var in object) {
code block to be executed
}
var myArr = {
name : 'Bhumi',
sname : 'Golakia',
age : 22
}
alert( myArr['name'] ); //Bhumi
for( var i in myArr ){
console.log("At key "+i+" got "+myArr[i]+" value.");
}
while loop:
This loop control the flow of code depend on condition. this loop checks the condition first and then it will do increments or decrements
syntax :
while (condition) {
code block to be executed
}
while ( i < 10 ) {
console.log(i); //0,1,2,3,4,5,6,7,8,9
i++;
};
Do while loops:
This loop first do the increment or decrements and the it checks the condition. Control flow statement that executes a block of code at least once.
syntax:
do {
code block to be executed
}
while (condition);
do {
console.log("before: "+i);//0,1,2,3,4,5,6,7,8,9
i++;
}
while ( i < 10 );
Source: http://admec-multimedia-institute.blogspot.in/2016/06/basics-concepts-of-javascript.html