Introduction to JavaScript
1. JavaScript (JS) is a high-level, interpreted scripting language
which is used for client-side web development.
2. It enables dynamic interactivity on web pages, manipulates
content in real-time, and supports event driven, asynchronous,
and object-oriented programming paradigms.
3. JavaScript executes in web browsers (client-side) and via
platforms like Node.js (server-side).
4. Features of JavaScript -
1. Dynamic Typing
i. In JavaScript, you don’t need to declare the data type of
a variable in advance.
ii. The JavaScript engine decides the data type at runtime.
2. Platform Independent
i. JavaScript is a platform-independent language, or we
can say it is portable, which means you can simply
write the script once and run it anywhere and
anytime.
ii. With the use of JavaScript, you can write your code for
web applications and run them on any platform or any
browser without any issues with the output of
JavaScript.
3. Interpreted Language
i. JavaScript was a purely interpreted language that
means the code executed line by line by the browser.
ii. JavaScript Engine like v8 (used in chrome and nodejs )
use
Just-In-Time Compiler (JIT)
1. java/c++ -----> compile- -> run
2. JavaScript -------------------> run
3. Code is interpreted at first and compiled to
machine code for faster performance
iii. JavaScript Engine -
1. Chrome - v8
2. Edge - chakra
3. Firfox - spidermonkey
4. Safari - JavaScriptCore
5. Single-Threaded
i. JavaScript is single-threaded by default; it does not
support multi-threading, which means it only executes
a single task at a time.
ii. A thread is a smallest unit of a process that the
operating system can schedule for execution block of
code
iii. Event loop handles the async task (multi stack task) in
the background.
iv. JavaScript has some features that you can use to
implement parallel execution. They are as follows:
Asynchronous processing (with callbacks,
promises, async/await)
6. Client-side validation
i. JavaScript is frequently used to validate
form inputs directly in the browser —
ensuring users submit correct information.
7. Backend Development
i. By using JavaScript, backend development
can also be done with Node.js. MERN stack
is one of the most popular stacks based on
JavaScript for full-stack development using
JavaScript.
History
1. In 1995 Brendan Eich invented the JavaScript
Language.
2. The company behind JavaScript is Netscape
Communication
Standardization (1997)
1. JavaScript was standardized under the name
ECMAScript (ES)
2. The full form of ECMA, as in ECMAScript, is European
Computer Manufacturers Association.
3. First version was ECMAScript 1 - ES1
4. Current Version - ES14
ClientSide vs ServerSide
1) ServerSide scripting is done at the backend where the source
code is hidden on the client side(Browser) and the ClientSide
scripting is done at the front end which users can access or
manipulate them on Browser.
2) ClientSide scripting works faster than ServerSide Scripting.
3) ClientSide scripting is less secure than ServerSide scripting
because users has the access of client side script.
4) ServerSide script is run on remote local server and ClientSide
script is run on local computer.
JavaScript Program to Print
There are three ways to print 'Hello, World!'.
○ document.write()
○ A document.write() is a function you can use
when you want to print the content to the HTML
document.
○ alert()
○ In JavaScript, the alert() method is used to
display an alert box over the current window
with the specified message.
○ console.log()
○ In JavaScript, the console.log is a function
that is used to log messages on the web
console.