BASIC SYNTAX OF JAVASCRIPT

  1. Variables: Variables are like containers that hold information. They can store numbers, words, or other types of data.

    var number = 5;
    var greeting = "Hello!";
  2. Functions: Functions are like small programs. That tells the computer to do a specific task, and it follows the instructions.

    function addNumbers(a, b)
    {
        return a + b;
    }
    var result = 
    addNumbers(3, 4);
  3. Conditions: We can make the computer decide what to do based on certain conditions. For example, if a number is greater than 0, do one thing; otherwise, do something else.

    var number = 5;
    if (number > 0)
    {
    console.log("Positive number");
    }
    else
    {
    console.log("Negative number");
    }
  4. Loops: Loops help us to repeat tasks. If we want to do something several times, we can use a loop.

    for (var i = 0; i < 5; i++)
    {
    console.log(i);
    }
  5. Objects: Objects are like containers that can hold multiple pieces of information. Each piece is called a property.

    var person = { name: "John", age: 30, isStudent: false, };
  6. Arrays: Arrays are like lists where you can store multiple items.

    var colors = ["red", "green", "blue"];
  7. Event Handling: You can make things happen on a webpage in response to user actions, like clicking a button.

    document.getElementById("myButton").addEventListener("click", function() { console.log("Button clicked!"); });
  8. Comments: Comments are notes in the code for us or others to understand what's happening. They don't affect how the code runs.

    // This is a comment

Comments

Popular posts from this blog

Java Program to create a large array and copy its values equally to two small arrays and display the second array only

Python program to sum up the Salary when the Name and Age matches with subsequent rows.