{"id":95,"date":"2026-05-01T15:32:25","date_gmt":"2026-05-01T15:32:25","guid":{"rendered":"https:\/\/gigz.pk\/javascript\/?post_type=lesson&#038;p=95"},"modified":"2026-05-01T15:32:26","modified_gmt":"2026-05-01T15:32:26","slug":"function-declaration","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/javascript\/?lesson=function-declaration","title":{"rendered":"Function Declaration"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Function declaration is one of the most important concepts in JavaScript. It allows developers to define reusable blocks of code that perform specific tasks. Instead of writing the same code multiple times, a function lets you write it once and use it whenever needed.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A function declaration defines a named function using the function keyword. This type of function can be called anywhere in the code because it is hoisted, meaning JavaScript reads it before executing the program.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Syntax of Function Declaration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A function declaration starts with the function keyword, followed by the function name, parentheses, and a code block.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function greet() {<br>  console.log(\"Hello, Welcome to JavaScript\");<br>}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">To run the function, you simply call its name.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>greet();<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Function with Parameters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Functions can take inputs called parameters. These parameters allow the function to work with different values.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function greetUser(name) {<br>  console.log(\"Hello \" + name);<br>}<br><br>greetUser(\"Ali\");<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Function with Return Value<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Functions can also return a value using the return keyword. This allows the result to be stored or used later.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function add(a, b) {<br>  return a + b;<br>}<br><br>let result = add(5, 3);<br>console.log(result);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Key Characteristics of Function Declaration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Function declarations are hoisted so they can be used before they are defined<br>They must have a name<br>They help organize code into reusable blocks<br>They improve readability and maintainability<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">When to Use Function Declaration<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Use function declarations when you need reusable logic<br>When building structured and organized programs<br>When creating functions that should be accessible throughout the code<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Function declaration is a foundational concept in JavaScript that helps developers write clean, reusable, and efficient code. Mastering it is essential for building real-world applications.<\/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 Declaration<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777649516179\"><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-1777649515976\"><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-95","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 Declaration - Learn JavaScript with GIGZ.PK<\/title>\n<meta name=\"description\" content=\"Learn JavaScript function declaration with examples, parameters, and return values to write reusable and efficient code 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-declaration\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Function Declaration - Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"og:description\" content=\"Learn JavaScript function declaration with examples, parameters, and return values to write reusable and efficient code easily\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/javascript\/?lesson=function-declaration\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-01T15:32:26+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-declaration\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=function-declaration\",\"name\":\"Function Declaration - Learn JavaScript with GIGZ.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\"},\"datePublished\":\"2026-05-01T15:32:25+00:00\",\"dateModified\":\"2026-05-01T15:32:26+00:00\",\"description\":\"Learn JavaScript function declaration with examples, parameters, and return values to write reusable and efficient code easily\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=function-declaration#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=function-declaration\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=function-declaration#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Intermediate JavaScript > Functions > Function Declaration\"}]},{\"@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 Declaration - Learn JavaScript with GIGZ.PK","description":"Learn JavaScript function declaration with examples, parameters, and return values to write reusable and efficient code 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-declaration","og_locale":"en_US","og_type":"article","og_title":"Function Declaration - Learn JavaScript with GIGZ.PK","og_description":"Learn JavaScript function declaration with examples, parameters, and return values to write reusable and efficient code easily","og_url":"https:\/\/gigz.pk\/javascript\/?lesson=function-declaration","og_site_name":"Learn JavaScript with GIGZ.PK","article_modified_time":"2026-05-01T15:32:26+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-declaration","url":"https:\/\/gigz.pk\/javascript\/?lesson=function-declaration","name":"Function Declaration - Learn JavaScript with GIGZ.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/javascript\/#website"},"datePublished":"2026-05-01T15:32:25+00:00","dateModified":"2026-05-01T15:32:26+00:00","description":"Learn JavaScript function declaration with examples, parameters, and return values to write reusable and efficient code easily","breadcrumb":{"@id":"https:\/\/gigz.pk\/javascript\/?lesson=function-declaration#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/javascript\/?lesson=function-declaration"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/javascript\/?lesson=function-declaration#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/javascript"},{"@type":"ListItem","position":2,"name":"Intermediate JavaScript > Functions > Function Declaration"}]},{"@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\/95","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=95"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}