{"id":97,"date":"2026-05-01T15:35:30","date_gmt":"2026-05-01T15:35:30","guid":{"rendered":"https:\/\/gigz.pk\/javascript\/?post_type=lesson&#038;p=97"},"modified":"2026-05-01T15:35:31","modified_gmt":"2026-05-01T15:35:31","slug":"function-expressions","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/javascript\/?lesson=function-expressions","title":{"rendered":"Function Expressions"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">Introduction<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Function expressions are a way of defining functions in JavaScript by assigning them to variables. Unlike function declarations, function expressions are not hoisted, meaning they cannot be used before they are defined in the code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">They are widely used in modern JavaScript for callbacks, event handling, and creating flexible code structures.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is a Function Expression<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A function expression defines a function inside an expression and stores it in a variable. It can be anonymous or named.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const greet = function() {<br>  console.log(\"Hello, world\");<br>};<br><br>greet();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here the function is stored in a variable called greet and called using that variable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Named Function Expression<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A function expression can also have a name which is useful for debugging.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const greetUser = function welcome() {<br>  console.log(\"Welcome user\");<br>};<br><br>greetUser();<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The function is still accessed through the variable even if it has an internal name.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Key Features of Function Expressions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Functions are stored in variables<br>They are not hoisted<br>They can be anonymous or named<br>They are commonly used in callbacks<br>They support flexible programming patterns<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Difference Between Function Declaration and Function Expression<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Function Declaration<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function sayHello() {<br>  console.log(\"Hello\");<br>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Function Expression<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const sayHello = function() {<br>  console.log(\"Hello\");<br>};<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Function declarations can be used before they are defined but function expressions cannot.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Use Cases of Function Expressions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Event handling in websites<br>Callback functions like map and filter<br>Storing functions in variables<br>Creating reusable code blocks<br>Asynchronous programming<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example with Callback<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>const numbers = &#91;1, 2, 3, 4];<br><br>const doubled = numbers.map(function(num) {<br>  return num * 2;<br>});<br><br>console.log(doubled);<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Advantages<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Makes code flexible<br>Helps in writing clean structure<br>Important for modern frameworks<br>Useful in functional programming<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Conclusion<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Function expressions are an important part of JavaScript that help developers write flexible and reusable code. They are widely used in real-world web development.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/javascript\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Intermediate JavaScript > Functions > Function Expressions<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777649693584\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777649693375\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"menu_order":0,"template":"","class_list":["post-97","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Function Expressions - Learn JavaScript with GIGZ.PK<\/title>\n<meta name=\"description\" content=\"Learn JavaScript function expressions with examples, syntax, and uses in callbacks and modern web development easily.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/javascript\/?lesson=function-expressions\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Function Expressions - Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"og:description\" content=\"Learn JavaScript function expressions with examples, syntax, and uses in callbacks and modern web development easily.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/javascript\/?lesson=function-expressions\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-01T15:35:31+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=function-expressions\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=function-expressions\",\"name\":\"Function Expressions - Learn JavaScript with GIGZ.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\"},\"datePublished\":\"2026-05-01T15:35:30+00:00\",\"dateModified\":\"2026-05-01T15:35:31+00:00\",\"description\":\"Learn JavaScript function expressions with examples, syntax, and uses in callbacks and modern web development easily.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=function-expressions#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=function-expressions\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=function-expressions#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Intermediate JavaScript > Functions > Function Expressions\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/\",\"name\":\"Learn JavaScript with GIGZ.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Function Expressions - Learn JavaScript with GIGZ.PK","description":"Learn JavaScript function expressions with examples, syntax, and uses in callbacks and modern web development easily.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/javascript\/?lesson=function-expressions","og_locale":"en_US","og_type":"article","og_title":"Function Expressions - Learn JavaScript with GIGZ.PK","og_description":"Learn JavaScript function expressions with examples, syntax, and uses in callbacks and modern web development easily.","og_url":"https:\/\/gigz.pk\/javascript\/?lesson=function-expressions","og_site_name":"Learn JavaScript with GIGZ.PK","article_modified_time":"2026-05-01T15:35:31+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/javascript\/?lesson=function-expressions","url":"https:\/\/gigz.pk\/javascript\/?lesson=function-expressions","name":"Function Expressions - Learn JavaScript with GIGZ.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/javascript\/#website"},"datePublished":"2026-05-01T15:35:30+00:00","dateModified":"2026-05-01T15:35:31+00:00","description":"Learn JavaScript function expressions with examples, syntax, and uses in callbacks and modern web development easily.","breadcrumb":{"@id":"https:\/\/gigz.pk\/javascript\/?lesson=function-expressions#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/javascript\/?lesson=function-expressions"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/javascript\/?lesson=function-expressions#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/javascript"},{"@type":"ListItem","position":2,"name":"Intermediate JavaScript > Functions > Function Expressions"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/javascript\/#website","url":"https:\/\/gigz.pk\/javascript\/","name":"Learn JavaScript with GIGZ.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/javascript\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson\/97","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}