What is Function Expression in JavaScript | Functions | JavaScript

preview_player
Показать описание
In JavaScript, there is another way of creating functions apart from function declaration syntax - Function expression.

A function expression is just another syntax for creating a function in JavaScript where you can assign an anonymous function to a variable. Then using the variable name you can execute or call that function.

Let's understand how to create and use a function expression in JavaScript with some examples.
Рекомендации по теме
Комментарии
Автор

Thank you, you were very clear, concise, and understandable, a great help!

gcambrose
Автор

GREAT EXPLANATIONS AGAIN, THANKS A LOT!

hannabouttros
Автор

Coding Challenge #javascriptFunctions
Challenge 1
Create a function expression with mainFunc as the variable name, which takes only one parameter of function type and calls that function inside the mainFunc.

Hint: create a secondary function that has a simple console.log method with any string.
Challenge 2
Create a function addNum which takes 2 parameters. The first is an integer value and the other is a function type parameter. When addNum is invoked(called), it should return the sum of the first parameter and the return value from the second parameter(which is 10 here).
Hint: the second function should return 10.
Challenge 3
Given an array of cars manufacturers whose values are given below. The array doesn’t have uniformity in the values. Create a function that takes the manufacturers as a single parameter returns an object having 2 keys ‘allLowerCase’ and ‘allUpperCase’ whose values are processed values in lower case and upper case respectively.
manufacturers = ['audi', 'BMw', 'ForD', 'mG', 'tata', 'MAHINDRA'];

TheMarketingManU