DEV Community

Cover image for 100 days of Miva: Day 9
Abdulsamod
Abdulsamod

Posted on

2

100 days of Miva: Day 9

Day 9 of the 100 days of Miva coding challenge. Big progress has been made on my understanding of JavaScript.

Today, I learned about functions on JavaScript. Functions are very useful in JavaScript as they allow us to reuse code and also avoid mistakes due to code duplication. Thanks to W3schools, I was able to learn and practice functions and operations related to them. Let's dive in!

Creating Functions
Functions are created by using the function keyword, followed by parenthesis containing the parameters required for executing the function. The return keyword is used to state which operation is to be performed on the parameter(s) and what value to return to the user.

Creating Functions

Using Functions outputs as variable values
Outputs of functions can be assigned to variable names after the function has been executed.

Variable Values

Functions have various uses and can be used to perform different types of operations ranging from arithmetic operations, logical operations and executing conditional statements. Here is an example of a function used to convert units:

Unit Conversion

Values obtained from these operations can be embedded in HTML programs that require values obtained from these functions.

Embedding outputs in texts

Local Variables
In JavaScript, variables declared within a function are known as local variables and do not exist outside of the function. Hence, a new variable can be declared with the same name outside of the function which is normally not allowed.

Local Variables

Functions are very important in JavaScript as they make coding easier and cleaner. They allow code reusability and serve as mini libraries where outputs can be pulled for use in other parts of code.

That's it on JavaScript Functions. Hoping to explore more and share with you in the coming days! Source code can be seen here: https://github.com/Abdul-Samod/100daysofMiva/blob/ce61cd46cefb40058a83276484d45b1b27c27a38/javascript_prac2.html

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (1)

Collapse
 
tobidelly profile image
TD!

w3School, building devs

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay