Curriculum
Course: JavaScript Basics
Login

Curriculum

JavaScript Basics

Text lesson

Lesson 3: JavaScript Syntax and Basics

JavaScript Syntax and Basics

Understanding the basic syntax of JavaScript is fundamental to writing effective code. In this lesson, we’ll cover the essential syntax rules, including statements, comments, and case sensitivity.

1. JavaScript Statements:

  • JavaScript programs are composed of statements, which are instructions to be executed by the browser.
  • Each statement ends with a semicolon (;), although this is optional in most cases.

2. JavaScript Comments:

  • Comments are used to explain code and make it more readable. They are ignored by the browser.
  • Single-line comments start with //.
  • Multi-line comments are enclosed in /* */.

3. Case Sensitivity:

  • JavaScript is case-sensitive. Variables, function names, and other identifiers must be typed with consistent capitalization.

Example Code:

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Syntax</title>
</head>
<body>
<h1>JavaScript Syntax and Basics</h1>
<script>
// This is a single-line comment
console.log('Hello, JavaScript!'); // Output a message to the console

/* This is a
multi-line comment */

console.log('Learning JavaScript syntax.');
</script>
</body>
</html>

 

4. Displaying Output:

  • Use console.log() to display output in the browser console.
  • Use alert() to show an alert box with a message.

 

Conclusion: Mastering the basic syntax of JavaScript is the first step towards becoming a proficient programmer. Practice writing statements, using comments, and understanding case sensitivity to build a strong foundation.

Layer 1
Login Categories
This website uses cookies and asks your personal data to enhance your browsing experience.