📚 A function is a block of organized, reusable code used to perform specific actions or tasks.
Functions are the backbone of efficiency. They can encapsulate a set of instructions and be called or invoked multiple times throughout a program. This feature promotes code reuse, readability, and modularity, which are invaluable during development!
🔍 Example with console.log()
`console.log()` is a built-in function in JavaScript that allows you to log output to the console. You can use it to display messages, debug code, or perform various tasks.
Try this in your DevTools:
<pre class="preFormatted"><code class="codeFormatted">
console.log("Hello World");
// Output: Hello World
</code></pre>
Or perform a mathematical operation like:
<pre class="preFormatted"><code class="codeFormatted">
console.log(1 + 5);
// Output: 6
</code></pre>
Open the browser's DevTools with F12, navigate to the Console tab, and try these examples for yourself!
Published: June 2024
← Back to Blog