IT CHAP 3 JAVASCRIPT

Cards (59)

  • Scripting Language
    A type of programming language that is designed for scripting or automating specific tasks
  • Unlike traditional programming languages like C++ or Java, scripting languages are typically interpreted rather than compiled
  • Scripts are executed directly by an interpreter, line by line, without the need for a separate compilation step
  • Types of Scripting Language in Web Development
    • Client-Side Scripting Language
    • Server-Side Scripting Language
  • Client-side scripting languages
    Programming languages that run on the user's web browser (client-side) to interact with web pages and modify their behavior dynamically
  • Client-side scripts
    Embedded directly into the HTML code of the web page and executed on the client's device
  • Primary purpose of client-side scripting
    To enhance the user experience by adding interactivity and responsiveness to the web page without requiring constant communication with the server
  • Server-side scripting languages
    Programming languages that run on the web server to process requests, perform business logic, and generate dynamic content to be sent back to the client-side (web browser)
  • Server-side scripts
    Executed on the server, and the results are delivered to the client in the form of HTML, CSS, JavaScript, or other data formats
  • JavaScript
    A high-level, client-side scripting language/programming language primarily used for web development
  • JavaScript was created by Brendan Eich while he was working at Netscape Communications Corporation
    1995
  • JavaScript is now one of the most popular and widely used programming languages in web development due to its versatility and ability to create interactive and dynamic web pages
  • Role of JavaScript in web development
    Allows developers to add interactivity and functionality to websites
  • While HTML and CSS handle the structure and presentation of web pages, JavaScript enhances the user experience by enabling actions like form validation, handling user interactions, creating animations, and updating content dynamically without requiring a page reload
  • Embedded Script
    Adding JavaScript code directly within the HTML file by placing the JavaScript code inside <script> tags
  • Advantages of Embedded Script
    • Adding JavaScript inline is a fast way to include small snippets of code directly within the HTML structure
    • Embedded Script can easily access and manipulate the HTML elements within the same document
  • Disadvantages of Embedded Script
    • For larger projects, embedding JavaScript within HTML can lead to a lack of separation of concerns and make the codebase harder to maintain
    • If the same JavaScript code is required on multiple pages, it needs to be duplicated in each HTML file
  • External JavaScript
    Creating a separate .js file containing the JavaScript code and linking it to the HTML file using the <script> element's src attribute
  • Advantages of External JavaScript
    • External JavaScript files promote code modularity and organization, making it easier to manage and maintain a large codebase
    • The same JavaScript file can be linked to multiple HTML files, reducing code duplication and improving maintainability
    • External JavaScript files can be cached by the browser, leading to faster page loading times for subsequent visits to the website
  • Disadvantage of External JavaScript
    • The web browser needs to fetch the external JavaScript file, which may slightly increase the initial page load time
  • Statement
    A command that tells the browser what to do
  • Script
    A series of statements
  • Semicolon
    Tells JavaScript that it's the end of the command
  • Comments
    Provide reminders and explanations throughout the code that are ignored at the time the script is executed
  • Single-line comments
    Use two slash characters (//) at the beginning of the line
  • Multiple-line comments
    Use the same syntax as CSS, everything within the /* */ characters is ignored by the browser
  • Variables
    Used to store data in JavaScript, act as containers that hold different types of values
  • JavaScript data types
    • Numbers
    • Strings
    • Booleans
    • Undefined
    • Null
    • Objects
    • Arrays
  • Variable declaration
    Using the var, let, or const keyword, depending on the scope and mutability requirements
  • Operators
    Used to perform operations on data, such as arithmetic, comparison, logical, assignment, and more
  • Arithmetic operators
    • +
    • -
    • *
    • /
    • %
    • ++
    • --
  • Comparison operators
    • ==
    • !=
    • ===
    • !==
    • >
    • <
    • >=
    • <=
  • Conditional statements
    Allow developers to execute different blocks of code based on certain conditions
  • if-else statement

    Evaluates a condition, and if it's true, it executes a specific block of code. If the condition is false, an optional else block can be executed.
  • switch statement

    Used for multi-way branching, checks the value of an expression against various cases and executes the code block associated with the matching case
  • Loops
    Used to execute a block of code repeatedly until a certain condition is met
  • for loop
    Executes a block of code a specific number of times
  • if-else statement

    A conditional statement that checks a condition, and if it's true, it executes a specific block of code. If the condition is false, an optional else block can be executed.
  • switch statement

    Used for multi-way branching. It checks the value of an expression against various cases and executes the code block associated with the matching case.
  • Loops
    • Used to execute a block of code repeatedly until a certain condition is met. JavaScript supports different types of loops.