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

JavaScript Vs Java

Uploaded by

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

JavaScript Vs Java

Uploaded by

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

JavaScript vs Java

Java JavaScript
Java is a strongly typed language JavaScript is a loosely typed
and variables must be declared first language and has a more relaxed
to use in the program. In Java, the syntax and rules.
type of a variable is checked at
compile-time.
Java is an object-oriented JavaScript is a scripting
programming language primarily language used for creating
used for developing complex interactive and dynamic web pages.
enterprise applications.
Java applications can run in any JavaScript code used to run only in
virtual machine(JVM) or browser. the browser, but now it can run on
the server via Node.js.
Objects of Java are class-based JavaScript Objects are prototype-
even we can’t make any program in based.
java without creating a class.
Java program has the file extension JavaScript file has the file extension
“.Java” and translates source code “.js” and it is interpreted but not
into bytecodes which are executed compiled, every browser has the
by JVM(Java Virtual Machine). Javascript interpreter to execute JS
code.if compile time
Java is a Standalone language. contained within a web page and
integrates with its HTML content.
Java has a thread-based approach Javascript has an event-based
to concurrency. approach to concurrency.
Java supports multithreading, which JavaScript does not support
allows multiple threads of execution multithreading, although it can
to run concurrently within a single simulate it through the use of web
program. workers.
Java is mainly used for backend Javascript is used for the frontend
and backend both.
Java is statically typed, which JavaScript is dynamically typed,
means that data types are which means that data types are
determined at compile time. determined at runtime.
Java uses more memory Javascript uses less memory.
Java requires a Java Development Javascript requires any text editor
Kit(JDK) to run the code or browser console to run the code.

What are JavaScript Data Types?


There are three major Data types in JavaScript.
Primitive
- Numbers
- Strings
- Boolean
- Symbol
Trivial
- Undefined
- Null
Composite
- Objects
- Functions
- Arrays

What is negative infinity?


The negative infinity is a constant value represents the lowest available value. It
means that no other number is lesser than this value. It can be generate using a
self-made function or by an arithmetic operation. JavaScript shows the
NEGATIVE_INFINITY value as -Infinity.

Which company developed JavaScript?


Netscape developed JavaScript and was created by Brenden Eich in the year of
1995.
Write a JavaScript code for adding new elements dynamically.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>

<body>
<button onclick="create()">
Click Here!
</button>

<script>
function create() {
let geeks = document.createElement('geeks');
geeks.textContent = "Geeksforgeeks";
geeks.setAttribute('class', 'note');
document.body.appendChild(geeks);
}
</script>
</body>
</html>

JavaScript has three kind of popup boxes: Alert box, Confirm box, and Prompt box.
Alert:
alert("I am an alert box!");
Confirm:
if (confirm("Press a button!")) {
txt = "You pressed OK!";
} else {
txt = "You pressed Cancel!";
}
Prompt:
let person = prompt("Please enter your name", "Harry Potter");
let text;
if (person == null || person == "") {
text = "User cancelled the prompt.";
} else {
text = "Hello " + person + "! How are you today?";
}

This Keyword in JavaScript


ViewState and SessionState
Timers in JavaScript
Loops in JavaScript
TextContent vs InnerHTML vs InnerText
Event Bubbling
Errors in JavaScript
Closures in JavaScript
Event Loop and asynchronous programming

You might also like