Course Content
Data types and Values
0/1
Object-oriented programming in JavaScript
0/1
Error handling and debugging in JavaScript
0/1
JavaScript functions for string and array manipulation
0/1
JavaScript Libraries and Frameworks
0/1
JavaScript
About Lesson

JavaScript syntax and variables

JavaScript syntax is based on a combination of C-style syntax and functional programming. Here are some key aspects of JavaScript syntax:

  • Statements: JavaScript programs consist of statements, which are instructions that are executed in a particular order.
  • Variables: Variables are used to store data in JavaScript. They are declared using the “let”, “var”, or “const” keywords, and can be assigned a value using the assignment operator “=”.

Examples:

let myVariable = 42;

  • Data Types: JavaScript has several data types, including numbers, strings, booleans, null, and undefined.

Examples

let myNumber = 42;

let myString = “Hello, world!”;

let myBoolean = true;

let myNull = null;

let myUndefined = undefined;

  • Operators: JavaScript has several operators for performing arithmetic, comparison, and logical operations.

Examples:

let sum = 10 + 5; // Adds 10 and 5

let isEqual = 10 === 5; // Compares if 10 is equal to 5

let andResult = true && false; // Performs the logical AND operation on true and false

  • Functions: Functions are used to encapsulate code and perform specific tasks. They are declared using the “function” keyword, and can take parameters and return values.

Examles:

function addNumbers(num1, num2) {

  return num1 + num2;

}

let result = addNumbers(10, 5); // Calls the addNumbers function and assigns the result to the “result” variable

JavaScript variables can be declared using the “let”, “var”, or “const” keywords. The “let” keyword is used to declare a variable that can be reassigned a value, while the “const” keyword is used to declare a variable that cannot be reassigned a value. The “var” keyword is an older way to declare variables that can be reassigned a value, but it is now generally recommended to use “let” instead.