Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

Sorry, you do not have permission to ask a question, You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please type your username.

Please type your E-Mail.

Please choose an appropriate title for the post.

Please choose the appropriate section so your post can be easily searched.

Please choose suitable Keywords Ex: post, video.

Browse

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Logo

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Navigation

  • Home
  • About Us
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Contact Us
Home/ Questions/Q 2443

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise Latest Questions

Author
  • 61k
Author
Asked: November 26, 20242024-11-26T05:27:07+00:00 2024-11-26T05:27:07+00:00

JavaScript Fundamentals: Mutable let,Comments, Functions

  • 61k

Today is the 2nd day of my #100DaysOfCode journey with JavaScript.

I am going to write about my learnings in an explained way through my blogs and socials. If you want to join me on the learning journey, make sure to follow my blogs and social and share yours too. Let's learn together!🫱🏼‍🫲🏼

This Article is a part of the JavaScript Fundamentals series*.*

Mutable let

We worked on variables in the last section and now going further with variables, how can we change the stored value inside of a variable?

We used const keyword to declare a constant variable, but if we try to change the value it will give errors.

const a = 4; a = 8; 
Enter fullscreen mode Exit fullscreen mode

If we try to run above the line, it will give TypeError: Assignment to constant variable . Constants are immutable, meaning their value cannot change.

Here comes the keyword let which allows the value to be mutable (meaning it can change).

let a = 4; a = 8; 
Enter fullscreen mode Exit fullscreen mode

The above line will run without error.

Comments

Comments are an important part of programs. Writing good comments is also necessary to be a good programmer and to write clean code.

Coming up with good variable names is also important.

const value = 99; const price = 99; 
Enter fullscreen mode Exit fullscreen mode

Both hold the same value 99 but price is more descriptive.

Comments are only for humans to understand code in a better way. We can write single-line or multi-line comments.

// this is price in U.S. Dollars const price = 99; 
Enter fullscreen mode Exit fullscreen mode

/* The price of all items    Denominated in U.S. Dollars  */ const price = 99; 
Enter fullscreen mode Exit fullscreen mode

Functions

A function is a reusable code and it returns an output. The function must be defined before calling it. Function call means to execute the function. The word invoke is also used and the meaning is the same as call.

When a function is called, It means you're passing specific input values.

const output = addOne(5); 
Enter fullscreen mode Exit fullscreen mode

In the code above, addOne is the function and parenthesis ( ) is used to call the function. We are passing in an input value 5 into our function addOne.

It is not mandatory to have input values in the function. See the below example.

const message = getMessage(); 
Enter fullscreen mode Exit fullscreen mode

In order to call a function, we must first define it!

function addOne(input) {     return input + 2; } 
Enter fullscreen mode Exit fullscreen mode

In the above code, we are creating a function called addOne which takes one input called input. We are returning the input plus two.

function getMessage() {     return "Hello World!"; } 
Enter fullscreen mode Exit fullscreen mode

In the above code, function getMessage does not take input. We are simply returning a string, saying “Hello World!”. The return statement will return the desired output of the function.

const a = addOne(2); 
Enter fullscreen mode Exit fullscreen mode

Variable a is now assigned to the return value of the addOne function invoked with an input of 2, which evaluates to 4.

Conclusion

Ending with an extra bit of information about JavaScript functions…

If we define/declare a function once, it can be called elsewhere in the program.

Today I learned about Mutable let, Comments, and Functions in JavaScript.

If You ❤️ My Content! Connect Me on Twitter or Supports Me By Buying Me A Coffee☕

100daysofcodejavascripttutorialwebdev
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question

Stats

  • Questions 4k
  • Answers 0
  • Best Answers 0
  • Users 2k
  • Popular
  • Answers
  • Author

    Insights into Forms in Flask

    • 0 Answers
  • Author

    Kick Start Your Next Project With Holo Theme

    • 0 Answers
  • Author

    Refactoring for Efficiency: Tackling Performance Issues in Data-Heavy Pages

    • 0 Answers

Top Members

Samantha Carter

Samantha Carter

  • 0 Questions
  • 20 Points
Begginer
Ella Lewis

Ella Lewis

  • 0 Questions
  • 20 Points
Begginer
Isaac Anderson

Isaac Anderson

  • 0 Questions
  • 20 Points
Begginer

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help

Footer

Querify Question Shop: Explore Expert Solutions and Unique Q&A Merchandise

Querify Question Shop: Explore, ask, and connect. Join our vibrant Q&A community today!

About Us

  • About Us
  • Contact Us
  • All Users

Legal Stuff

  • Terms of Use
  • Privacy Policy
  • Cookie Policy

Help

  • Knowledge Base
  • Support

Follow

© 2022 Querify Question. All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.