What is JavaScript?

JavaScript is a programming language that is commonly used to add dynamic features to websites. 

It is a client-side scripting language, which means that the source code is processed by the client’s web browser rather than on the server. 

JavaScript can also be run on the server side using technologies such as Node.js. 

It is an object-oriented language and it is also used to create cross-platform applications.

What are some JavaScript examples ?

Here are a few examples of JavaScript code:

  • Displaying an alert box:

alert(“Hello, World!”);

  • Changing the content of a webpage:

document.getElementById(“myHeading”).innerHTML = “Hello, World!”;

  • Creating a function:

function addNumbers(a, b) {

    return a + b;

}

  • Using an if-else statement:

if (x > 10) {

    console.log(“x is greater than 10”);

} else {

    console.log(“x is not greater than 10”);

}

  • Creating an object:

let person = {

    firstName: “John”,

    lastName: “Doe”,

    age: 30

};

These are just a few examples of the many things that can be done with JavaScript.