General and Web Programming Fundamentals
  • Introduction
  • Program creation and design
    • Program design
      • Algorithms
      • Pseudocode
    • Programming conventions
    • Writing programs
      • Source code editors
      • Integrated Development Environments
      • Code repositories/Version control
      • Compilers/Interpreters
  • Programming Fundamentals
    • Operators
      • Arithmetic
      • Logical
      • Assignment
    • Constants and Variables
    • Datatypes
      • Primitive Datatypes
        • Character
        • Integer
        • Boolean
        • Floating point
        • Nothing (Null)
      • Composite Datatypes
        • Arrays
        • Strings
        • Classes
        • Structs
      • Literals
    • Data structures
      • Lists
      • Queues
      • Stacks
      • Map/dictionary
      • Trees
      • Graphs
    • Control structures
      • Selection (Conditional)
        • If/Else
        • Ternary
        • Switch
      • Iteration (Loops)
        • For loops
        • While loops
        • Do-While loops
        • For-Each loops
    • Functions
      • Parameters and arguments
      • Lambda expressions
      • Higher Order Functions
    • Space and Time
    • Scope
    • Standard libraries
  • Programming Paradigms
    • Procedural (Imperative) Programming
    • Object-oriented programming
    • Functional Programming
    • Declarative Programming
    • Event Driven programming
  • Programming Languages
    • Short history of programming
    • Low-level programming languages
    • High-level programming languages
  • Web Development
    • What is the web?
      • Web browsers (clients)
      • Webservers (serving web pages)
      • W3C
    • Markup languages
      • HTML
        • HTML Tags
      • Cascading Style Sheets (CSS)
        • CSS Properties
      • XML
      • Markdown
    • Scripting Languages
      • JavaScript
      • TypeScript
    • JSON
    • JavaScript Frameworks
  • Acknowledgements
    • About the author(s)
  • License
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. Web Development
  2. Scripting Languages

JavaScript

JavaScript is a programming language that was created by Brendan Eich in 1995 while he was an engineer at Netscape. Originally developed under the name Mocha, it was later renamed to LiveScript, and finally to JavaScript. Despite its name, JavaScript is not directly related to the Java programming language.

The main purpose of JavaScript when it was designed was to enable dynamic web content. This includes tasks like updating content on a webpage without reloading the page, form validation before submission, and creating interactive elements such as games and animations. JavaScript has evolved significantly since its inception and has become a cornerstone of the modern web, playing a central role in the development of web applications.

Current Use

Today, JavaScript is not just limited to client-side scripting in browsers. It is also widely used for server-side programming, thanks to environments like Node.js. JavaScript is used for building a vast range of applications from simple websites to complex web applications like single-page applications (SPAs), mobile apps (with frameworks like React Native), and even desktop applications (using Electron).

JavaScript frameworks and libraries, such as Angular, React, and Vue.js, have also increased the popularity and usability of JavaScript by providing developers with robust tools and components to build responsive and dynamic user interfaces more efficiently.

JavaScript Syntax Example

Here’s a basic example of JavaScript syntax:

// defining a function
function greet(name) {
  alert("Hello, " + name + "!");
}

// calling the function
greet("World");

This simple script consists of defining a function named greet that takes one parameter name and shows an alert pop-up with a personalized greeting message. The function is then called with the argument "World".

Linking JavaScript Files to Web Pages

To link a JavaScript file to an HTML document, the <script> tag is used. This can be done in two main ways:

  1. Inline Script - Directly including JavaScript code within an HTML document between <script> tags:

  2. <script>
      // JavaScript code goes here
      alert("This is an inline script!");
    </script>
    1. External Script - Linking to an external .js file:

    2. <script src="path/to/your-script.js"></script>

      Using an external script is generally preferable for maintaining cleaner code and reusability across different parts of a web application.

      JavaScript, with its robust ecosystem and wide range of use cases, continues to be an essential part of web development and plays a pivotal role in defining interactive and dynamic user experiences on the web.

PreviousScripting LanguagesNextTypeScript

Last updated 1 year ago

Was this helpful?