Last updated Feb 9, 2021

Learn JavaScript from Scratch : The Ultimate Beginners Guide

In this post, we will learn JavaScript from the basics. Today JavaScript has become one of the most popular programming languages on the web and the good part of JavaScript is easy to learn.

Learn JavaScript from Scratch : The Ultimate Beginners Guide

In this post, we will learn JavaScript from the basics. Today JavaScript has become one of the most popular programming languages on the web and the good part of JavaScript is easy to learn.

In this tutorial, I will teach you some basics of javascript.

Learn JavaScript from Scratch

What is JavaScript?

A Programming language that is used to make web pages interactive.

JavaScript is an easy and lightweight programming language of HTML and web. It is open-source and cross-platform.

What Can I do with JavaScript?

  • To make Responsive webpages. 
  • Put content in an HTML page on the fly. 
  • Validate forms. 
  • Create Animations, Slideshows, Scrollers, etc

In this tutorial, I will teach the basic functionality of javascript to build dynamic web pages and web applications.

Read, 8 Most useful Jquery Selectors - You Need To Know

How to add JavaScript in HTML?

Way-1:

Include JS in an HTML page, you’ll need to wrap the code in <script> tags, like this:

<script type="text/javascript">

//Your JavaScript code goes here

</script>

Way-2:

When you have large code collection, then its better to create separate JavaScript file and put all logic there to make code more efficiency and then link to it in your HTML file. 

So if your file is named script.js, then here’s how to call it in your HTML file.

<script src="/script.js"></script>

How to do Comments in JavaScript?

In Programming, Comments are very useful because they help other people to understand and can help to debug your code when it’s needed.

There are two different ways to add comments to your JavaScript code:

Single-line comments:

Using the “//”(Double slash) to add single-line comments to your code.

// Single line comment in JS
let myVar= "Some Value"

Multi-line comments:

You can write  multi-line comments in your code by Wrapping your comments in /* and */ as the start and finish of your comment, like this:

/*
 Multi line comment in JS
*/

Let’s start, with a basic example,

In the following example, we will make simple popup box using Javascript.

Example:

<head>
    <title>Javascript Step by step</title>
    <script>
       //In name variable we will store value recived by popupbox
        var name =prompt('Please Enter Your Name:','Name');
       
        //now it print the value on browser in text format
        document.write('Hello'+' '+name+' '+'To my website');

    </script>

</head>
</html>

 so, in the above example, we created a simple popup box that receives value from the user and displays it on the browser in text format.

This is the basic example of javascript uses.

Now we will learn how to create functions in javascript.

How to Create Function In JavaScript?

Functions are a Very useful term of any programming language. It is the collection of code and it makes our code dynamic and reusable. so let’s start making the function in javascript by the following example:

Example:

<html>
<head>
<script>
        function sampleFunction(){
            var name = prompt('Please Enter Your Name:', 'Name');

            document.write('Hello' + 'name' + 'To my website');
        }
    </script>
</head>

<input type="button" value="Sample Function" />
</html>

 In the above example, we have created a function named ‘sampleFunction’ and called on the click event of the button. So when the user will click on the button a popup will open and ask for a name and display on the browser. So isn’t simple.

Also read, 12 Most Helpful jQuery Methods and Functions

Conclusion:

Do let me know If you face any difficulties please feel free to comment below we love to help you.if you have any feedback suggestion then please inform us by commenting.

Don’t forget to share this tutorial with your friends on Facebook and Twitter

Tags

Available for projectsLet’s build together

Need this built properly,
not just explained?

I take on Angular and NestJS work directly — auth systems, multi-tenant SaaS, API rewrites and the deploy pipeline underneath them. You talk to the person writing the code.

Projects delivered
20+ Projects delivered
Angular • NestJS
7+ years Angular • NestJS
Average reply time
1 day Average reply time

What I can help with

  • Auth and permissions systems
  • Multi-tenant SaaS foundations
  • API design and rewrites
  • Deploy pipelines and VPS setup
  • Bug fixing and performance optimization
Send me a message

Tell me about your project and I’ll get back with a realistic scope and price.

Turn
Your Ideas
Into Reality

Stay in the loop

Get the finished tutorials, projects and resources in your inbox.

Join 5,000+ developers and get new tutorials, source code, product updates and exclusive content — straight to your inbox.

  • No spam
  • Useful content only
  • Unsubscribe anytime

Subscribe to TutsCoder

Be the first to get new tutorials, projects and tips.

Join 5,000+ developers already learning with us.

Learn
Build
Grow

Discussion

Comments

Share your thoughts, ask questions or suggest improvements. Let’s learn and grow together!

Loading comments…

Join the discussion

Sign in to join the discussion. Your account also keeps your saved tutorials and path progress.