JavaScript syntax

JavaScript is a high-level, interpreted programming language that is widely used for developing web applications. Here is an example of JavaScript

syntax:

function calculateSum(num1, num2) {
  return num1 + num2;
}

let result = calculateSum(2, 3);
console.log(result);

The function calculateSum has been written in the example above to take two parameters, num1 and num2, and return their sum. Then, after calling this method with the arguments 2 and 3, we assigned the outcome to the result variable. Finally, we used the console.log function to output the outcome.


Using the script> tag, JavaScript code can be directly included in an HTML document. Alternatively, it can be placed in a separate.js file and accessed by using the src attribute of the script> tag.

Variables do not need to be specified with a particular data type because JavaScript is a dynamic language. For instance, we don’t need to indicate that x is an integer; we may just write let x = 5.

Numerous other data types, such as numbers, texts, booleans, arrays, objects, and functions are also supported by JavaScript. Additionally, if/else statements, loops, and switch statements are just a few of the control structures that JavaScript allows.