1. Write your first Javascript function with Emojis

1. Write your first Javascript function with Emojis

ยท

2 min read

Learning about basic data structures in Javascript is a lifetime reward

So let's get right into the topic. Functions are a block of code that executes the commands or the logic it contains. There are two types of functions

  1. Hard-coded functions

  2. Dynamic Functions

First, let's take a look at Hard-coded Functions. Ever bought a baby doll that plays a song when you hit a button?

Play with the below makeFriends() function and let's analyze it below

Code Playground

  1. Try with different emojis

  2. Remove the double quotes and try to run the program

Notice here that every time you call the function it's simply gonna add those two emojis and logs it out no matter what. This is called a hard-coded function.

Analysis

Let's Analyse-it.

When you write your function you gonna write it by defining it as a "function" and you are gonna name it using camelCase, especially in JS. In Python, you will be using PascalCase. You can read more about it in detail here.

Step 1

In our case let's name it makeFriends() since this function makes everyone inside it friends by bringing them together. And add our lion and tiger emojis then returning it

function makeFriends() {
      return "๐Ÿฆ" + "๐Ÿฏ"
}

Step 2

If we write our function without return we will get no output. As for javascript, we need to log it in the console for output.

console.log(makeFriends())

Output

"๐Ÿฆ๐Ÿฏ"

Whole Function

function makeFriends() {
      return "๐Ÿฆ" + "๐Ÿฏ"

}

console.log(makeFriends())

Pat yourself on the back cause you just wrote your first javascript function and it works ๐ŸŽ‰

In the next article, we will learn about dynamic functions ๐Ÿ‘‹

ย