Functions allow programmers to organize code into reusable units and divide large programs into smaller, more manageable parts. The document discusses key concepts related to functions in Python like defining and calling user-defined functions, passing arguments, scope, and recursion. It provides examples of different types of functions and how concepts like mutability impact parameter passing. Functions are a fundamental part of modular and readable program design.
Functions allow programmers to organize code into reusable blocks. A function performs a specific task and can accept input parameters and return an output. Functions make code more modular and easier to maintain. Functions are defined with a name, parameters, and body. They can be called from other parts of the code to execute their task. Parameters allow functions to accept input values, while return values allow functions to return output to the calling code. Functions can be called by passing arguments by value or reference. The document provides examples and explanations of different types of functions in C++ like inline functions, functions with default arguments, and global vs local variables.
This document discusses functions in C programming. It defines functions as a group of statements that perform a specific task and have a name. Main functions must be included in every C program as it is where program execution begins. Functions help facilitate modular programming by dividing programs into smaller parts. Functions can be user-defined or built-in library functions. Parameters can be passed to functions by value or by reference. Functions can call themselves through recursion. Variables have different storage classes like auto, register, static, and external that determine scope and lifetime.
Functions are self-contained blocks of code that perform specific tasks. There are library functions provided by the C standard and user-defined functions created by programmers. Functions make programs clearer and easier to debug by separating code into logical units. Functions can call themselves recursively to perform repetitive tasks. Functions are defined with a return type, name, and parameters, and code is passed between functions using call-by-value parameter passing. Function prototypes declare functions before they are used.
The document discusses different ways to declare variables in JavaScript. There are three main keywords: var, let, and const. Var declares variables with function scope, let declares block-scoped variables, and const declares block-scoped variables that cannot be reassigned.
FUNCTION IN C PROGRAMMING UNIT -6 (BCA I SEM)Mansi Tyagi
A function is a block of code that performs a specific task. There are two types of functions: library functions and user-defined functions. User-defined functions are created by the programmer to perform specific tasks within a program. Recursion is when a function calls itself during its execution. For a recursive function to terminate, it must have a base case and each recursive call must get closer to the base case. An example is a recursive function to calculate the factorial of a number. Storage classes determine where variables are stored and their scope. The main storage classes are automatic, register, static, and external.
Javascripts hidden treasures BY - https://geekyants.com/Geekyants
Closures and hoisting are hidden features in JavaScript that can cause confusion. Closures allow functions to access variables from outer scopes even after they have returned. Hoisting refers to variables and functions being declared at the top of their scope before code execution. Understanding closures and hoisting can help explain unexpected behavior, such as functions running before they are defined or variables printing undefined values.
The document introduces functions in C programming. It discusses defining and calling library functions and user-defined functions, passing arguments to functions, returning values from functions, and writing recursive functions. Functions allow breaking programs into modular and reusable units of code. Library functions perform common tasks like input/output and math operations. User-defined functions are created to perform specific tasks. Information is passed between functions via arguments and return values.
A function provides a convenient way of packaging a computational recipe, so that it can be used as often as required. A function definition consists of two parts: interface and body. The interface of a function (also called its prototype) specifies how it may be used. It consists of three entities:
The function name. This is simply a unique identifier.
The function parameters (also called its signature). This is a set of zero or more typed identifiers used for passing values to and from the function.
The function return type. This specifies the type of value the function returns. A function which returns nothing should have the return type void.
The body of a function contains the computational steps (statements) that comprise the function.
Functions allow programmers to structure code into modular, reusable units. A function contains a block of code that is executed when the function is called. Functions take parameters as input and can return a value. The example function "addition" takes two integer parameters, adds them together, and returns the result. The main function calls addition, passing it the values 5 and 3, and stores the returned value 8 in the variable z. Functions help avoid duplicating code and make programs easier to design, understand, and maintain.
Functions are JavaScript procedures that perform tasks and can be defined using the function keyword. Functions can have parameters and a body of statements. Functions allow for nested scopes where bindings inside functions are local while bindings outside any function are global. Function values can be passed as arguments, stored in bindings, and used similarly to other values. The call stack stores the context each time a function is called and removes it when the function returns.
The document discusses functions in Python. Some key points:
1. Functions allow programmers to split large programs into smaller, reusable units of code. This makes programs easier to understand, test, and maintain.
2. There are different types of functions like built-in functions, user-defined functions, and library functions that contain generic code.
3. Functions can take parameters and return values. Parameters are placeholders for values passed to the function while arguments are the actual values passed.
4. Functions have scopes that determine where variables are accessible. Local scope only allows access within the function while global scope allows access anywhere.
Storage class determines the accessibility and lifetime of a variable. The main storage classes in C++ are automatic, external, static, and register. Automatic variables are local to a function and are created and destroyed each time the function is called. External variables have global scope and persist for the lifetime of the program. Static variables also have local scope but retain their value between function calls.
slide1: the content of functons
slide2: Introduction to function
slide3:function advantages
slide4 -5: types of functions
slide6: elements of user defined functions
The document describes functions in Pascal programming. It defines what a function is, how it is similar to and different from procedures. It explains the parts of a function like arguments, return type, local declarations, and function body. It provides examples of a basic max function and how to declare, define, call and recursively call functions. It discusses acceptable return types and notes about short-circuit evaluation and passing functions as parameters.
The document discusses functions in Python. It introduces functions as a way to divide large programs into smaller, more manageable units called functions. Functions allow code to be reused by calling or invoking the function from different parts of a program. The document then covers key concepts related to functions like arguments, parameters, scope, recursion, and more. It provides examples to illustrate different types of functions and how concepts like scope, recursion, and argument passing work.
The document discusses storage classes and functions in C/C++. It explains the four storage classes - automatic, external, static, and register - and what keyword is used for each. It provides examples of how to declare variables of each storage class. The document also discusses different types of functions like library functions, user-defined functions, function declaration, definition, categories based on arguments and return values, actual and formal arguments, default arguments, and recursion.
This document discusses various C++ concepts related to functions including:
- Default pointers which receive addresses passed to called functions.
- Reference variables which receive the reference of an actual variable passed to a function. Changing the reference variable directly changes the actual variable.
- Inline functions which eliminate context switching when defined inside a class or declared with the inline keyword.
- Friend functions which have access to private/protected members of a class they are declared as a friend to.
C++ Object oriented concepts & programmingnirajmandaliya
This document discusses various C++ concepts related to functions and operators. It defines what a default pointer is and how it receives addresses passed to a called function. It also discusses reference variables, inline functions, friend functions, default arguments, passing objects as parameters, function overloading, static members, function pointers, and operator overloading. It provides examples and explanations for each concept.
The document discusses JavaScript functions as first-class objects that can be passed as arguments, returned from other functions, and stored in variables. It explains that functions can be defined using function declarations or function expressions. Function declarations are hoisted to the top of their scope, while function expressions must be assigned to variables. Immediately invoked function expressions (IIFEs) allow defining anonymous functions that execute right away, protecting private variables from polluting the global scope.
The document discusses functions in C programming. It defines a function as a self-contained program segment that carries out a specific task. Functions allow a program to be broken down into modular components. Functions can be called from anywhere in a program and allow information to be passed between the calling code and the function. Functions must be defined before use and include a return type, name, parameters, and function body. At most one value can be returned from a function.
Operator Overloading and Scope of VariableMOHIT DADU
This slide is completely based on the Operator Overloading and the Scope of Variable. The example given to explain are based on C/C++ programming language.
Overloaded functions allow multiple functions with the same name but different parameter types. This improves readability and handles incorrect arguments. The document provides examples of overloaded averaging and calculator functions. Pass by reference passes a variable's address rather than value, allowing the original variable to be modified. Scope defines variable visibility - variables are destroyed when exiting a scope unless declared static or global. Practice questions demonstrate overloaded functions, pass by reference, scopes, and static/global variables.
Coleoptera, commonly known as beetles, is the largest order of insects, comprising approximately 400,000 described species. Beetles can be found in almost every habitat on Earth, exhibiting a wide range of morphological, behavioral, and ecological diversity. They have a hardened exoskeleton, with the forewings modified into elytra that protect the hind wings. Beetles play important roles in ecosystems as decomposers, pollinators, and food sources for other animals, while some species are considered pests in agriculture and forestry.
Artificial intelligence Presented by JM.jmansha170
AI (Artificial Intelligence) :
"AI is the ability of machines to mimic human intelligence, such as learning, decision-making, and problem-solving."
Important Points about AI:
1. Learning – AI can learn from data (Machine Learning).
2. Automation – It helps automate repetitive tasks.
3. Decision Making – AI can analyze and make decisions faster than humans.
4. Natural Language Processing (NLP) – AI can understand and generate human language.
5. Vision & Recognition – AI can recognize images, faces, and patterns.
6. Used In – Healthcare, finance, robotics, education, and more.
Owner By:
Name : Junaid Mansha
Work : Web Developer and Graphics Designer
Contact us : +92 322 2291672
Email : [email protected]
More Related Content
Similar to 11_Functions_Introduction.pptx javascript notes (20)
The document introduces functions in C programming. It discusses defining and calling library functions and user-defined functions, passing arguments to functions, returning values from functions, and writing recursive functions. Functions allow breaking programs into modular and reusable units of code. Library functions perform common tasks like input/output and math operations. User-defined functions are created to perform specific tasks. Information is passed between functions via arguments and return values.
A function provides a convenient way of packaging a computational recipe, so that it can be used as often as required. A function definition consists of two parts: interface and body. The interface of a function (also called its prototype) specifies how it may be used. It consists of three entities:
The function name. This is simply a unique identifier.
The function parameters (also called its signature). This is a set of zero or more typed identifiers used for passing values to and from the function.
The function return type. This specifies the type of value the function returns. A function which returns nothing should have the return type void.
The body of a function contains the computational steps (statements) that comprise the function.
Functions allow programmers to structure code into modular, reusable units. A function contains a block of code that is executed when the function is called. Functions take parameters as input and can return a value. The example function "addition" takes two integer parameters, adds them together, and returns the result. The main function calls addition, passing it the values 5 and 3, and stores the returned value 8 in the variable z. Functions help avoid duplicating code and make programs easier to design, understand, and maintain.
Functions are JavaScript procedures that perform tasks and can be defined using the function keyword. Functions can have parameters and a body of statements. Functions allow for nested scopes where bindings inside functions are local while bindings outside any function are global. Function values can be passed as arguments, stored in bindings, and used similarly to other values. The call stack stores the context each time a function is called and removes it when the function returns.
The document discusses functions in Python. Some key points:
1. Functions allow programmers to split large programs into smaller, reusable units of code. This makes programs easier to understand, test, and maintain.
2. There are different types of functions like built-in functions, user-defined functions, and library functions that contain generic code.
3. Functions can take parameters and return values. Parameters are placeholders for values passed to the function while arguments are the actual values passed.
4. Functions have scopes that determine where variables are accessible. Local scope only allows access within the function while global scope allows access anywhere.
Storage class determines the accessibility and lifetime of a variable. The main storage classes in C++ are automatic, external, static, and register. Automatic variables are local to a function and are created and destroyed each time the function is called. External variables have global scope and persist for the lifetime of the program. Static variables also have local scope but retain their value between function calls.
slide1: the content of functons
slide2: Introduction to function
slide3:function advantages
slide4 -5: types of functions
slide6: elements of user defined functions
The document describes functions in Pascal programming. It defines what a function is, how it is similar to and different from procedures. It explains the parts of a function like arguments, return type, local declarations, and function body. It provides examples of a basic max function and how to declare, define, call and recursively call functions. It discusses acceptable return types and notes about short-circuit evaluation and passing functions as parameters.
The document discusses functions in Python. It introduces functions as a way to divide large programs into smaller, more manageable units called functions. Functions allow code to be reused by calling or invoking the function from different parts of a program. The document then covers key concepts related to functions like arguments, parameters, scope, recursion, and more. It provides examples to illustrate different types of functions and how concepts like scope, recursion, and argument passing work.
The document discusses storage classes and functions in C/C++. It explains the four storage classes - automatic, external, static, and register - and what keyword is used for each. It provides examples of how to declare variables of each storage class. The document also discusses different types of functions like library functions, user-defined functions, function declaration, definition, categories based on arguments and return values, actual and formal arguments, default arguments, and recursion.
This document discusses various C++ concepts related to functions including:
- Default pointers which receive addresses passed to called functions.
- Reference variables which receive the reference of an actual variable passed to a function. Changing the reference variable directly changes the actual variable.
- Inline functions which eliminate context switching when defined inside a class or declared with the inline keyword.
- Friend functions which have access to private/protected members of a class they are declared as a friend to.
C++ Object oriented concepts & programmingnirajmandaliya
This document discusses various C++ concepts related to functions and operators. It defines what a default pointer is and how it receives addresses passed to a called function. It also discusses reference variables, inline functions, friend functions, default arguments, passing objects as parameters, function overloading, static members, function pointers, and operator overloading. It provides examples and explanations for each concept.
The document discusses JavaScript functions as first-class objects that can be passed as arguments, returned from other functions, and stored in variables. It explains that functions can be defined using function declarations or function expressions. Function declarations are hoisted to the top of their scope, while function expressions must be assigned to variables. Immediately invoked function expressions (IIFEs) allow defining anonymous functions that execute right away, protecting private variables from polluting the global scope.
The document discusses functions in C programming. It defines a function as a self-contained program segment that carries out a specific task. Functions allow a program to be broken down into modular components. Functions can be called from anywhere in a program and allow information to be passed between the calling code and the function. Functions must be defined before use and include a return type, name, parameters, and function body. At most one value can be returned from a function.
Operator Overloading and Scope of VariableMOHIT DADU
This slide is completely based on the Operator Overloading and the Scope of Variable. The example given to explain are based on C/C++ programming language.
Overloaded functions allow multiple functions with the same name but different parameter types. This improves readability and handles incorrect arguments. The document provides examples of overloaded averaging and calculator functions. Pass by reference passes a variable's address rather than value, allowing the original variable to be modified. Scope defines variable visibility - variables are destroyed when exiting a scope unless declared static or global. Practice questions demonstrate overloaded functions, pass by reference, scopes, and static/global variables.
Coleoptera, commonly known as beetles, is the largest order of insects, comprising approximately 400,000 described species. Beetles can be found in almost every habitat on Earth, exhibiting a wide range of morphological, behavioral, and ecological diversity. They have a hardened exoskeleton, with the forewings modified into elytra that protect the hind wings. Beetles play important roles in ecosystems as decomposers, pollinators, and food sources for other animals, while some species are considered pests in agriculture and forestry.
Artificial intelligence Presented by JM.jmansha170
AI (Artificial Intelligence) :
"AI is the ability of machines to mimic human intelligence, such as learning, decision-making, and problem-solving."
Important Points about AI:
1. Learning – AI can learn from data (Machine Learning).
2. Automation – It helps automate repetitive tasks.
3. Decision Making – AI can analyze and make decisions faster than humans.
4. Natural Language Processing (NLP) – AI can understand and generate human language.
5. Vision & Recognition – AI can recognize images, faces, and patterns.
6. Used In – Healthcare, finance, robotics, education, and more.
Owner By:
Name : Junaid Mansha
Work : Web Developer and Graphics Designer
Contact us : +92 322 2291672
Email : [email protected]
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...parmarjuli1412
The document provides an overview of therapeutic communication, emphasizing its importance in nursing to address patient needs and establish effective relationships. THERAPEUTIC COMMUNICATION included some topics like introduction of COMMUNICATION, definition, types, process of communication, definition therapeutic communication, goal, techniques of therapeutic communication, non-therapeutic communication, few ways to improved therapeutic communication, characteristics of therapeutic communication, barrier of THERAPEUTIC RELATIONSHIP, introduction of interpersonal relationship, types of IPR, elements/ dynamics of IPR, introduction of therapeutic nurse patient relationship, definition, purpose, elements/characteristics , and phases of therapeutic communication, definition of Johari window, uses, what actually model represent and its areas, THERAPEUTIC IMPASSES and its management in 5th semester Bsc. nursing and 2nd GNM students
Strengthened Senior High School - Landas Tool Kit.pptxSteffMusniQuiballo
Landas Tool Kit is a very helpful guide in guiding the Senior High School students on their SHS academic journey. It will pave the way on what curriculum exits will they choose and fit in.
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...EduSkills OECD
Deborah Nusche, Senior Analyst, OECD presents at the OECD webinar 'Trends Spotting: Strategic foresight for tomorrow’s education systems' on 5 June 2025. You can check out the webinar on the website https://oecdedutoday.com/webinars/ Other speakers included: Deborah Nusche, Senior Analyst, OECD
Sophie Howe, Future Governance Adviser at the School of International Futures, first Future Generations Commissioner for Wales (2016-2023)
Davina Marie, Interdisciplinary Lead, Queens College London
Thomas Jørgensen, Director for Policy Coordination and Foresight at European University Association
A short update and next week. I am writing both Session 9 and Orientation S1.
As a Guest Student,
You are now upgraded to Grad Level.
See Uploads for “Student Checkin” & “S8”. Thx.
Thank you for attending our workshops.
If you are new, do welcome.
Grad Students: I am planning a Reiki-Yoga Master Course (As a package). I’m Fusing both together.
This will include the foundation of each practice. Our Free Workshops can be used with any Reiki Yoga training package. Traditional Reiki does host rules and ethics. Its silent and within the JP Culture/Area/Training/Word of Mouth. It allows remote healing but there’s limits As practitioners and masters. We are not allowed to share certain secrets/tools. Some content is designed only for “Masters”. Some yoga are similar like the Kriya Yoga-Church (Vowed Lessons). We will review both Reiki and Yoga (Master tools) in the Course upcoming.
Session Practice, For Reference:
Before starting a session, Make sure to check your environment. Nothing stressful. Later, You can decorate a space as well.
Check the comfort level, any needed resources (Yoga/Reiki/Spa Props), or Meditation Asst?
Props can be oils, sage, incense, candles, crystals, pillows, blankets, yoga mat, any theme applies.
Select your comfort Pose. This can be standing, sitting, laying down, or a combination.
Monitor your breath. You can add exercises.
Add any mantras or affirmations. This does aid mind and spirit. It helps you to focus.
Also you can set intentions using a candle.
The Yoga-key is balancing mind, body, and spirit.
Finally, The Duration can be long or short.
Its a good session base for any style.
Next Week’s Focus:
A continuation of Intuition Development. We will review the Chakra System - Our temple. A misguided, misused situation lol. This will also serve Attunement later.
For Sponsor,
General updates,
& Donations:
Please visit:
https://ldmchapels.weebly.com
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfChalaKelbessa
This is Forestry Exit Exam Model for 2025 from Department of Forestry at Wollega University, Gimbi Campus.
The exam contains forestry courses such as Dendrology, Forest Seed and Nursery Establishment, Plantation Establishment and Management, Silviculture, Forest Mensuration, Forest Biometry, Agroforestry, Biodiversity Conservation, Forest Business, Forest Fore, Forest Protection, Forest Management, Wood Processing and others that are related to Forestry.
RE-LIVE THE EUPHORIA!!!!
The Quiz club of PSGCAS brings to you a fun-filled breezy general quiz set from numismatics to sports to pop culture.
Re-live the Euphoria!!!
QM: Eiraiezhil R K,
BA Economics (2022-25),
The Quiz club of PSGCAS
*Order Hemiptera:*
Hemiptera, commonly known as true bugs, is a large and diverse order of insects that includes cicadas, aphids, leafhoppers, and shield bugs. Characterized by their piercing-sucking mouthparts, Hemiptera feed on plant sap, other insects, or small animals. Many species are significant pests, while others are beneficial predators.
*Order Neuroptera:*
Neuroptera, also known as net-winged insects, is an order of insects that includes lacewings, antlions, and owlflies. Characterized by their delicate, net-like wing venation and large, often prominent eyes, Neuroptera are predators that feed on other insects, playing an important role in biological control. Many species have aquatic larvae, adding to their ecological diversity.
Rose Cultivation Practices by Kushal Lamichhane.pdfkushallamichhame
This includes the overall cultivation practices of Rose prepared by:
Kushal Lamichhane (AKL)
Instructor
Shree Gandhi Adarsha Secondary School
Kageshowri Manohara-09, Kathmandu, Nepal
Pests of Rice: Damage, Identification, Life history, and Management.pptxArshad Shaikh
Rice pests can significantly impact crop yield and quality. Major pests include the brown plant hopper (Nilaparvata lugens), which transmits viruses like rice ragged stunt and grassy stunt; the yellow stem borer (Scirpophaga incertulas), whose larvae bore into stems causing deadhearts and whiteheads; and leaf folders (Cnaphalocrocis medinalis), which feed on leaves reducing photosynthetic area. Other pests include rice weevils (Sitophilus oryzae) and gall midges (Orseolia oryzae). Effective management strategies are crucial to minimize losses.
IDSP is a disease surveillance program in India that aims to strengthen/maintain decentralized laboratory-based IT enabled disease surveillance systems for epidemic prone diseases to monitor disease trends, and to detect and respond to outbreaks in the early phases swiftly.....
How to Create a Rainbow Man Effect in Odoo 18Celine George
In Odoo 18, the Rainbow Man animation adds a playful and motivating touch to task completion. This cheerful effect appears after specific user actions, like marking a CRM opportunity as won. It’s designed to enhance user experience by making routine tasks more engaging.
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxArshad Shaikh
Diptera, commonly known as flies, is a large and diverse order of insects that includes mosquitoes, midges, gnats, and horseflies. Characterized by a single pair of wings (hindwings are modified into balancing organs called halteres), Diptera are found in almost every environment and play important roles in ecosystems as pollinators, decomposers, and food sources. Some species, however, are significant pests and disease vectors, transmitting diseases like malaria, dengue, and Zika virus.
3. What Is A
Function ?
A function is a block of reusable code written to perform a
specific task. We can think of a function as a sub-program within
the main program.
.
A function consists of a set of statements but
executes as a single unit.
4. What Is A
Function ?
Functions are one of the fundamental concepts in programming.
They let us write modular, reusable,
and maintainable code
5. Examples Of Functions ?
JavaScript provides many built-in functions such as parseInt(),
parseFloat(), alert(), prompt(), confirm() etc
.
They all are predefined functions but now we will learn
how to develop user defined functions in JavaScript.
6. Types Of Functions ?
There are 3 popular types of functions we can develop in
JavaScript :
.
1. Named Function
2. Anonymous Function
3. Arrow Function
7. Steps Needed For Function ?
In JavaScript the function based programming approach requires
2 steps:
1. Defining the function
2. Calling the function
8. Syntax Of Defining A Function
Functions can be defined in both <head> and <body> section
but generally are placed in the head section.
<script>
function functionName( arg 1,arg 2. . .)
{
// some code
}
</script>
9. Syntax Of Calling A Function
<script>
functionName(arg 1,arg 2. . .);
</script>
10. Points To Remember
A function with no parameters must include a parenthesis after
it’s
name
*
The word “function” must be written in lowercase.
*
11. Using arguments Array
Whenever a function is invoked it gets an object called
“arguments” which acts like an array and holds the arguments
sent to that function.
This feature is very helpful if we don’t know how many arguments
might be passed to the function.
12. PROGRAM
Write a JavaScript function called “average( )” which
should accept some integers as argument and
calculates and displays their sum and average.
13. Calling Functions Via Button
A function can be called directly on a button click.
For this we need to assign the function call to the onclick event
attribute of the button tag.
Syntax:
<input type=“button” value=“some text”
onclick=“funcName();” >
14. Variable Scope
Variables declared outside a function, become GLOBAL, and all
scripts and functions on the web page can access it.
A variable declared (using var) within a JavaScript function
becomes LOCAL and can only be accessed from within that
function. (the variable has local scope).
If we assign a value to variable that has not yet been declared, the
variable will automatically be declared as a GLOBAL variable.
15. Returning Values
function functionName(var 1,var 2. . .)
{
// some code
return (variable or value);
}
To return a value from a function we use the keyword “return” .
The keyword return can only be used in a function.
16. A Very Important Point !!
In JavaScript functions are first-class citizens.
This means that we can:
1. store functions in variables
2. pass them as argument to other functions
3. return them from other functions.
In simple words, we can treat functions like values.
17. Anonymous Functions
Anonymous function is a function that does not have any name
associated with it.
Normally we use the function keyword before the function name to
define a function in JavaScript.
However, in anonymous functions in JavaScript, we use only the
function keyword without the function name.
18. Anonymous Functions
A function definition can be directly assigned to a variable .
This variable is like any other variable except that it’s value is a
function definition and can be used as a reference to that function.
Syntax:
var variablename = function(Argument List)
{
//Function Body
};
20. Some Important Built-In Functions
1. setInterval(function_name,time_period)
Accepts the name of a function and a time period in ms and calls
the function after the given ms , repeatedly. It also returns a
number representing the ID value of the timer that is set which can
be used with the clearInterval() method to cancel the timer
2. clearInterval(ID)
Clears the timer ,of the given ID ,set with the setInterval() method.
21. Some Important Built-In Functions
3. setTimeout(function_name,time_period)
Accepts the name of a function and a time period in ms and calls the
function after the given ms, only once. It also returns a number
representing the ID value of the timer that is set which can be used
with the clearTimeout() method to cancel the timer
4. clearTimeout(ID)
Clears the timer ,of the given ID , set with the setTimeout() method.
22. var v/s let
Now that we have learnt concept of functions , we must discuss
the difference between var and let keywords.
They differ in four ways:
1. Scope
2. Redeclaration
3. Window object
4. Using before declaring
23. Scope
Scope essentially means where these variables are available for
use.
var declarations are globally scoped or function/locally scoped ,
while let declarations are block scoped.
This means that a variable declared with var inside a function
anywhere is available through out that function while a let
variable declared inside a block is available only till the block
terminates
24. Scope
Example:
for (var i = 1; i <= 3; i++)
{
console.log(i);
}
console.log(i);
Output:
1
2
3
4
Example:
for (let i = 1; i <= 3; i++) {
console.log(i);
}
console.log(i);
Output:
1
2
3
Uncaught
ReferenceError: i is not
defined
25. Redeclaration
The var keyword allows us to redeclare a variable without any
issue.
var counter = 10;
var counter = 20;
console.log(counter); // 20
If we redeclare a variable with the let keyword, we will get an error:
let counter = 10;
let counter = 20; // error: x is already defined
26. The window Object
We know that a variable declared globally with var becomes a
property of window object but it is not true for variable declared
with let.
Example:
var x=10;
let y=20;
console.log(window.x);
console.log(window.y);
Output:
10
undefined
27. Using Before Declaring
We can use a variable created using var even before declaring it.
Example:
console.log(x);
var x=10;
console.log(x);
Output:
undefined
10
28. Using Before Declaring
However , let does not allow us to do this and so if we write the
previous code using let then JS will throw error:
Example:
console.log(x);
let x=10;
console.log(x);
Output:
Uncaught ReferenceError: Cannot access ‘x' before initialization.