0% found this document useful (0 votes)
4 views2 pages

JavaScript in Browser

JavaScript is used to create interactive web pages and is embedded within HTML using the <script> tag. Browsers have a JavaScript engine that enforces security limitations, preventing access to external sites. Developer tools, accessible via F12, provide functionalities like viewing elements, console logs, and network requests, while the console object offers methods for logging and managing outputs.

Uploaded by

kvishal88567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

JavaScript in Browser

JavaScript is used to create interactive web pages and is embedded within HTML using the <script> tag. Browsers have a JavaScript engine that enforces security limitations, preventing access to external sites. Developer tools, accessible via F12, provide functionalities like viewing elements, console logs, and network requests, while the console object offers methods for logging and managing outputs.

Uploaded by

kvishal88567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

JavaScript

JavaScript in the browser

• JavaScript was initially created to make web pages alive. JS can be written right in a web
page's HTML to make it interactive.

• The browser has an embedded engine called the JavaScript engine or the JavaScript runtime.

• JavaScript's ability in the browser is very limited to protect the user's safety. For example, a
webpage on http://google.com cannot access http://codeswear.com and steal information
from there!

• Every browser has some developer tools which makes a developer's life a lot easier.

• F12 on Chrome opens Dev Tools:

❖ Elements: all the elements in the HTML


❖ Console: all the errors and logs
❖ Network: all network requests
• We can also write JavaScript commands in the Console.
• The <script> tag is used to insert JavaScript into an HTML page.
• The script tag can be used to insert external or internal scripts

<script>
alert("Hello")
</script>
// or ....
<script src="/js/function.js"> </script>

• The benefit of a separate javascript file is that the browser will download it and store it in its
Cache.

Console Object Methods


The console object has several methods, log being one of them. Some of them are as
follows:
➢ assert() → Used to assert a condition
➢ clear() → Clears the console
➢ log() → Outputs a message to the Console
➢ table() → Displays a tabular data
➢ warn() → Used for warnings
➢ error() → Used for errors

Alert, Prompt and Confirm


i) Alert:
• Displays a pop-up window with a message and an "OK" button.
• Useful for simple notifications to the user.
• Example: alert("Hello, world!");

ii) Prompt:
• Displays a pop-up window with a message, an input field, and "OK" and
"Cancel" buttons.
• Allows the user to input text.
• Returns the input value or null if the user cancels.
• Example: let name = prompt("What is your name?");

iii) Confirm:
• Displays a pop-up window with a message and "OK" and "Cancel" buttons.
• Asks the user to make a decision.
• Returns true if the user clicks "OK" and false if the user clicks "Cancel."
• Example: let answer = confirm("Are you sure you want to proceed?");

Window object, BOM & DOM


We have the following when JavaScript runs in a browser
Window

DOM BOM JavaScript Core


Window object represents browser window and provides methods to control it. It is a global
object

You might also like