DEV Community

swetha palani
swetha palani

Posted on

JAVASCRIPT

1. What is JavaScript?

Javascript is high level interpreted programming language and interactive web page, most popular programming language.

Javascript is used to create interactive and dynamic web page. It is resposible and adding functionality to a website ad allows for user interaction with website's content

2: What is the difference between JavaScript and Java?

  • JavaScript is an interpreted, lightweight programming language, whereas Java is a compiled, heavyweight programming language.
  • JavaScript mainly runs in web browsers for client-side scripting, and also on servers using Node.js. Java runs on the Java Virtual Machine (JVM), making it platform-independent.
  • JavaScript is loosely typed, meaning variables can change type at runtime. Java is strongly typed, so variable types must be declared and cannot change.
  • JavaScript uses a prototype-based object model, while Java uses a class-based object model.
  • JavaScript supports asynchronous programming using event loops, promises, and async/await. Java supports true multi-threading.
  • JavaScript is mainly used for web interactivity and DOM manipulation, while Java is used for desktop applications, Android apps, and large-scale backend systems.

Example in JavaScript:

console.log("Hello from JavaScript!");
Enter fullscreen mode Exit fullscreen mode

Example in Java:

System.out.println("Hello from Java!");
Enter fullscreen mode Exit fullscreen mode

3.What are the features of JavaScript?

Lightweight and Interpreted – Runs directly in browsers without compilation.

Cross-Platform – Works on all modern browsers and environments.

Event-Driven and Asynchronous – Supports non-blocking operations.

Prototype-Based OOP – Uses prototypes instead of classical inheritance.

Dynamic Typing – Variables can hold any data type at runtime.

First-Class Functions – Functions can be treated as values, passed as arguments, or returned.

Rich Ecosystem – Vast libraries and frameworks (React, Angular, Vue, Node.js

  1. What is a variable in JavaScript?

A variable in JavaScript is a named container used to store data values that can be referenced and manipulated in your code. You declare variables using var, let, and const.

Declared using:

var → Function-scoped (older style).

let → Block-scoped (modern and flexible).

const → Block-scoped, but value cannot be reassigned.

JavaScript is dynamically typed, so a variable can hold any data type (string, number, object, etc.) and can even change its type at runtime.

// Using var
var name = "Swetha";  
console.log(name); // Output: Swetha

// Using let
let age = 22;  
age = 23; // Reassigning is allowed
console.log(age); // Output: 23

// Using const
const country = "India";  
// country = "USA"; // ❌ Error: Cannot reassign const
console.log(country); // Output: India

Enter fullscreen mode Exit fullscreen mode

Always prefer let or const for modern JavaScript. Use const by default unless reassignment is required.

Top comments (0)