Introduction to JavaScript Basics

Sep 16, 2024

JavaScript Introduction

Overview

  • Starting a new series on JavaScript from beginner to advanced level.
  • Focus of this video: Introduction to JavaScript and writing a simple "Hello World" program.

What is JavaScript?

  • JavaScript is a programming language, similar to Java, C, C++, etc.
  • Primarily made for web applications to add functionality.
  • Common misconception: JavaScript is related to Java; this is false.
    • Example: The word "car" in "carpet" has no relation; similarly, Java and JavaScript are unrelated.
    • JavaScript is a standalone language.

How to Use JavaScript

  • Two methods to include JavaScript in web applications:
    1. Internal Linking: Write JavaScript code directly inside the HTML file.
    2. External Linking: Create a separate .js file and link it to the HTML.

Internal Linking Example

  • Create an index.html file with basic HTML structure:
    • Use the <script> tag for JavaScript code.
    • Example of printing to the console:
      console.log("Hello World");
      
    • Access output via browser's console (Inspect element > Console).

External Linking Example

  • Create a script.js file to hold the JavaScript code.
  • Link it in the HTML:
    <script src="script.js"></script>
    
  • Code example in script.js:
    console.log("This is a hello from external.js file");
    

Combining Internal and External Scripts

  • You can mix internal and external scripts in the same HTML document:
    • Order of scripts matters (runs top to bottom).
  • Example of including multiple scripts:
    <script src="script.js"></script>
    <script>console.log("Hey again from internal script");</script>
    

Key Takeaways

  • JavaScript can be linked internally or externally; external linking is preferred for larger projects.
  • Use of <script> tag for both internal and external links.
  • Multiple JavaScript files can be linked and executed in a sequence.

Conclusion

  • This video covered the basics of JavaScript, including how to write a "Hello World" program and the best practices for linking JavaScript in HTML.
  • Upcoming videos will delve deeper into JavaScript concepts.