> For the complete documentation index, see [llms.txt](https://university-west.gitbook.io/programming-paradigms/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://university-west.gitbook.io/programming-paradigms/web-development/scripting-languages/javascript.md).

# 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:

```javascript
// 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. ```html
   <script>
     // JavaScript code goes here
     alert("This is an inline script!");
   </script>
   ```
   2. **External Script** - Linking to an external `.js` file:
   3. ```html
      <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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://university-west.gitbook.io/programming-paradigms/web-development/scripting-languages/javascript.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
