
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
How to define a JavaScript function using the expression?
To understand the concept of a JavaScript function using the expression, let us see the difference between Function Declaration and Function expression.
Function Declaration
The “function” keyword declares a function in JavaScript. To define a function in JavaScript use the “function” keyword, followed by a unique function name, a list of parameters (that might be empty), and a statement block surrounded by curly braces.
Here’s an example −
function sayHello(name, age) { document.write (name + " is " + age + " years old."); }
Function Expression
Function Expression should not start with the keyword “function”. Functions defined can be named or anonymous.
Here are the examples −
//anonymous function expression var a = function() { return 5; }
Or
//named function expression var a = function bar() { return 5; }
- Related Articles
- How to define a JavaScript function using Function() Constructor?
- How to define a Regular Expression in JavaScript?
- How to define a function in JavaScript?
- How to define global variable in a JavaScript function?
- How do we use function literal to define a function in JavaScript?
- How to define a function Using the WITH clause in Oracle?
- How to define functions inside a function body in JavaScript?
- How to define rest parameter for a function in JavaScript?
- How to define an Arrow Function in JavaScript?
- How to define custom sort function in JavaScript?
- How to delay a JavaScript function call using JavaScript?
- Function Expression vs Function Declaration in JavaScript?
- Named function expression in JavaScript
- How to define a function in Python?
- How to load a JavaScript function using the variable name?

Advertisements