0% found this document useful (0 votes)
7 views

Introduction to JavaScript

JavaScript is a versatile, dynamically typed programming language used for interactive web applications, supporting both client-side and server-side development. It features client-side scripting, event-driven capabilities, and a rich ecosystem of libraries and frameworks, while also being both compiled and interpreted for performance. Despite its strengths, JavaScript has limitations such as security risks, performance issues for complex tasks, and weak error handling.

Uploaded by

Maya Lee
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Introduction to JavaScript

JavaScript is a versatile, dynamically typed programming language used for interactive web applications, supporting both client-side and server-side development. It features client-side scripting, event-driven capabilities, and a rich ecosystem of libraries and frameworks, while also being both compiled and interpreted for performance. Despite its strengths, JavaScript has limitations such as security risks, performance issues for complex tasks, and weak error handling.

Uploaded by

Maya Lee
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Introduction to JavaScript

JavaScript is a versatile(having many different uses), dynamically


typed programming language used for interactive web applications,
supporting both client-side and server-side development, and integrating
seamlessly with HTML, CSS, and a rich standard library.
 JavaScript is a single-threaded language that executes one task at a
time.
 It is an Interpreted language which means it executes the code line by
line.
 The data type of the variable is decided at run-time in JavaScript
that’s why it is called dynamically typed.
 You don't have to get or download JavaScript.
 JavaScript is already running in your browser on your
computer, on your tablet, and on your smart-phone.
 JavaScript is free to use for everyone.

“Hello, World!” Program in Browser Console


<html>
<head></head>
<body>
<h1>Check the console for the message!</h1>
<script>
// This is our first JavaScript program
console.log("Hello, World!");
</script>
</body>
</html>

In this example
 The<script> tag is used to include JavaScript code inside an HTML
document.
 console.log() prints messages to the browser’s developer console.
Open the browser console to see the “Hello, World!” message.
“Hello World” Program in Server Console
/*
This is a multi-line comment.
It can span several lines.
*/
console.log("Hello, World!"); // Prints Hello, World! to the
console

 console.log(): The console.log() method is used to print messages


to the browser’s developer console. Open the console (usually with
F12 or Ctrl + Shift + J) to see the message “Hello, World!”
displayed.
o Multi-line Comment: The /* */ syntax is used to write a
comment spanning multiple lines.
o Single-line Comment: The // syntax is used for short, inline
comments, like the one explaining the console.log function.

Key Features of JavaScript


Here are some key features of JavaScript that make it a powerful
language for web development:
 Client-Side Scripting:JavaScript runs on the user’s browser, so
has a faster response time without needing to communicate with
the server.
 Versatile: JavaScript can be used for a wide range of tasks, from
simple calculations to complex server-side applications.
 Event-Driven: JavaScript can respond to user actions (clicks,
keystrokes) in real-time.
 Asynchronous: JavaScript can handle tasks like fetching data
from servers without freezing the user interface.
 Rich Ecosystem: There are numerous libraries and
frameworks built on JavaScript, such as React, Angular, and Vue.js,
which make development faster and more efficient.
Applications of JavaScript
JavaScript is used in a wide range of applications, from enhancing
websites to building complex applications. Here are some examples:
 Web Development: JavaScript adds interactivity and dynamic
behavior to static websites, with popular frameworks
like AngularJS enhancing development.
 Web Applications: JavaScript powers robust web applications,
leveraging APIs, React, and Electron to create dynamic user
experiences like Google Maps.
 Server Applications: Node.js brings JavaScript to the server side,
enabling powerful server applications and full-stack development.
 Game Development: JavaScript, combined with HTML5 and
libraries like Ease JS, enables the creation of interactive games for
the web.
 Smartwatches: Pebble JS allows JavaScript to run on
smartwatches, supporting apps that require internet connectivity.

Is JavaScript Compiled or Interpreted or both ?


JavaScript is both compiled and interpreted. The V8 engine improves
performance by first interpreting code and then compiling frequently
used functions for speed. This makes JavaScript efficient for modern
web apps. It’s mainly used for web development but also works in
other environments. You can learn it through tutorials and examples.
Just-In-Time (JIT) compilation is a technique used by JavaScript
engines (like V8) to improve performance. Here’s how it works
 Interpretation: Initially, the code is interpreted line-by-line by the
engine.
 Hot Code Detection: The engine identifies frequently executed
code, such as often-called functions.
 Compilation: The “hot” code is compiled into optimized machine
code for faster execution.
 Execution: The compiled machine code is then executed directly,
improving performance compared to repeated interpretation.
 JIT compilation balances between interpretation (for quick startup)
and compilation (for faster execution).

Limitations of JavaScript
Despite its power, JavaScript has some limitations to consider:
 Security Risks : JavaScript can be used for attacks like Cross-Site
Scripting (XSS), where malicious scripts are injected into a website
to steal data by exploiting elements like <img>, <object>, or <script>
tags.
 Performance : JavaScript is slower than traditional languages for
complex tasks, but for simple tasks in a browser, performance is
usually not a major issue.
 Complexity : To write advanced JavaScript, programmers need to
understand core programming concepts, objects, and both client-
and server-side scripting, which can be challenging.
 Weak Error Handling and Type Checking : JavaScript is weakly
typed, meaning variables don’t require explicit types. This can lead
to issues as type checking is not strictly enforced.

JavaScript Versions
Let’s take a look at the different versions of ECMAScript, their release
years, and the key features they introduced

Versio Releas
n Name e Year Features

ECMAScrip
ES1 t1 1997 Initial Release
ECMAScrip
ES2 t2 1998 Minor Editorial Changes

Added:
 Regular Expression
 try/catch
ECMAScrip  Exception Handling
ES3 t3 1999
 switch case and do-while

ECMAScrip
ES4 t4 Abandoned due to conflicts

Added:
 JavaScript “strict mode”
ECMAScrip  JSON support
ES5 t5 2009
 JS getters and setters

Added:
 let and const
 Class declaration
 import and export
ECMAScript  for..of loop
ES6 2015 2015
 Arrow functions
Added:
 Block scope for variable
 async/await
ECMAScrip  Array.includes function
ES7 t 2016 2016
 Exponentiation Operator

Added:
 Object.values
 Object.entries
ECMAScrip
ES8 t 2017 2017  Object.getOwnPropertiesDescripto
rs

Added:
ECMAScrip  spread operator
ES9 t 2018 2018
 rest parameters

Added:
 Array.flat()
ECMAScrip  Array.flatMap()
ES10 t 2019 2019
 Array.sort is now stable

Added:
ECMAScrip  BigInt primitive type
ES11 t 2020 2020
 nullish coalescing operator
Added:
ECMAScrip  String.replaceAll() Method
ES12 t 2021 2021
 Promise.any() Method

Added:
 Top-level await
ECMAScrip  New class elements
ES13 t 2022 2022
 Static block inside classes

Added:
 toSorted method
 toReversed method

ECMAScrip  findLast, and findLastIndex


ES14 t 2023 2023 methods on Array.prototype and
TypedArray.prototypet

You might also like