Skip to main content

JavaScript Syntax | Statements and Comments - Variables and Data Types - Operators and Control Flow Statements - Functions in Syntax of JavaScript

JavaScript Syntax:

JavaScript is a versatile scripting language that is primarily used for client-side web development. Here are some key elements of JavaScript syntax:

1. Statements and Comments:

Statements: JavaScript code is composed of statements, which are instructions that perform actions. Statements are typically terminated by a semicolon (`;`).

javascript
  var x = 5;  // Variable declaration and assignment statement
  console.log(x);  // Function call statement


Comments: Comments are used to add explanatory notes to the code. Single-line comments start with `//`, and multi-line comments are enclosed between `/*` and `*/`.

javascript
  // This is a single-line comment
  
  /*
  This is a
  multi-line comment
  */

Statements and Comments - Variables and Data Types - Operators and Control Flow Statements - Functions in Syntax of JavaScript
JavaScript Syntax

2. Variables and Data Types:

Variables:Variables are used to store and represent data. In JavaScript, you can use the `var`, `let`, or `const` keyword to declare variables.

javascript
  var name = "John";  // Variable declaration with initial value
  let age = 25;        // Variable declaration with let
  const pi = 3.14;     // Variable declaration with const


Data Types: JavaScript has dynamic typing, meaning the data type of a variable is determined at runtime. Common data types include numbers, strings, booleans, objects, arrays, and functions.

javascript
  var num = 42;          // Number
  var text = "Hello";    // String
  var flag = true;       // Boolean
  var person = {         // Object
      firstName: "John",
      lastName: "Doe"
  };
  var numbers = [1, 2, 3]; // Array

3. Operators:

JavaScript supports various operators for performing operations on variables and values.

Arithmetic Operators:

javascript
  var sum = 5 + 3;
  var difference = 8 - 3;
  var product = 4 * 2;
  var quotient = 10 / 2;

Comparison Operators:

javascript
  var isEqual = (a === b);
  var isNotEqual = (a !== b);
  var greaterThan = (x > y);
  var lessThanEqual = (x <= y);

Logical Operators:

javascript
  var andCondition = (a && b);
  var orCondition = (x || y);
  var notOperator = !isTrue;

4. Control Flow Statements:

Conditional Statements:

javascript
  if (condition) {
      // Code to execute if the condition is true
  } else {
      // Code to execute if the condition is false
  }

Loops:

javascript
  for (var i = 0; i < 5; i++) {
      // Code to repeat in each iteration
  }

  while (condition) {
      // Code to repeat as long as the condition is true
  }

Switch Statement:

javascript
  switch (expression) {
      case value1:
          // Code to execute if expression equals value1
          break;
      case value2:
          // Code to execute if expression equals value2
          break;
      default:
          // Code to execute if expression doesn't match any case
  }

5. Functions:

Functions are blocks of reusable code that can be defined and called.

javascript
function greet(name) {
    return "Hello, " + name + "!";
}

var greeting = greet("John");
console.log(greeting);

This is a basic overview of JavaScript syntax. JavaScript is a versatile language with many features, and its syntax allows developers to create dynamic and interactive web applications.

Comments

Popular posts from this blog

Best Money Earning Apps in India 2026 – Online Jobs & Income Guide

Best Apps to Earn Money Online in India (2026 Guide) Introduction With the rapid growth of Technology and digital platforms, earning Money online in India has become easier than ever. From students to professionals, everyone is exploring online Jobs and Business opportunities using mobile apps. In this blog, we will explore the Best Apps to Earn Money Online in India , along with selection process, benefits, earning power, and latest developments. Why Choose Money Earning Apps? Online earning apps are becoming popular due to: Flexible working hours No high investment required Easy to start with basic skills Opportunity to build a scalable Business Increasing demand due to Latest Development in digital economy Best Apps to Earn Money Online in India 1. Meesho Category: Reselling Business Earn by selling products without investment Share products via WhatsApp & social media Profit margin depends on pricing Best For: Housewives, beginners, side income seekers 2. Upwork Category...

New Technology Trends That Will Change India Jobs

New Technology Trends That Will Change India: Jobs, Money, Business & Future Opportunities: India is rapidly transforming into a technology-driven economy. With the rise of AI, automation, and digital platforms, new Technology trends are not only shaping industries but also creating new Jobs , boosting Business , and opening multiple ways to earn Money . In this blog, we will explore the latest developments, future job roles, selection process, benefits, and the power these technologies hold in shaping India’s future. Introduction: Why Technology Trends Matter in India India’s digital growth is fueled by government initiatives, startups, and global investments. The integration of Technology in sectors like agriculture, healthcare, education, and finance is creating massive opportunities. These trends are directly impacting: Job creation Business growth Income opportunities Skill demand Top New Technology Trends That Will Change India 1. Artificial Intelligence (AI) & Automati...

Biography of Manohar Joshi

Biography of Manohar Joshi: Manohar Gajanan Joshi is an Indian politician who has played a significant role in Maharashtra state politics. Born on December 2, 1937, in a middle-class family in a village called Ganeshpeth in Ratnagiri district, Maharashtra, Joshi's journey into politics was marked by his association with the Shiv Sena, a right-wing regional political party in India. Joshi's political career began in the late 1960s when he joined the Shiv Sena, which was then led by its founder, Bal Thackeray. He quickly rose through the ranks of the party due to his organizational skills, dedication, and ideological alignment with the party's principles, which advocated for the interests of the Marathi-speaking population of Maharashtra. In 1972, Manohar Joshi won his first election to the Brihanmumbai Municipal Corporation (BMC), marking the beginning of his electoral career. He served as a corporator in the BMC and later became the Mayor of Mumbai in 1976. Joshi's tenu...