0% found this document useful (0 votes)
6 views6 pages

What Is JavaScript

JavaScript is a high-level, interpreted programming language primarily used for creating dynamic web content and is also utilized on servers with Node.js. It features various data types, including primitive and non-primitive types, and has specific rules regarding variable declarations with var, let, and const, as well as concepts like hoisting and strict mode. Additionally, JavaScript supports object-oriented programming and higher-order functions, making it versatile for web development compared to Java, which is a compiled, statically typed language used for larger applications.

Uploaded by

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

What Is JavaScript

JavaScript is a high-level, interpreted programming language primarily used for creating dynamic web content and is also utilized on servers with Node.js. It features various data types, including primitive and non-primitive types, and has specific rules regarding variable declarations with var, let, and const, as well as concepts like hoisting and strict mode. Additionally, JavaScript supports object-oriented programming and higher-order functions, making it versatile for web development compared to Java, which is a compiled, statically typed language used for larger applications.

Uploaded by

jayesh11111soni
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

What is JavaScript?

JavaScript is a **high-level, interpreted, single-threaded, and asynchronous**


programming language. Its primary role is to enable **dynamic and interactive
content** on the client-side of the web, making websites engaging. Beyond the
browser, it's also widely used on servers with [Link].

What is Debugger?
The term "debugger" in JavaScript, as in many other programming languages,
refers to a specialized tool or feature designed to identify, analyze, and rectify
errors (bugs) within software code.
Q: What are the Data Types in JavaScript? Can you explain Primitive vs.
Non-Primitive types?
Yes, certainly.
In JavaScript, data types are broadly classified into two categories:
1. Primitive Data Types
These are basic, immutable data types. They represent a single value and are
stored by value.
JavaScript has 7 primitive types:
1. String – Textual data
2. Number – Both integers and floating points
3. Boolean – true or false
4. Undefined – A variable declared but not assigned a value
5. Null – Represents an intentional absence of value
6. BigInt – For integers larger than 2^53 - 1
7. Symbol – Unique and immutable value, often used as object keys
Key Feature: Primitives are immutable—once created, their value can’t be
changed directly.
2. Non-Primitive (Reference) Data Types
These are more complex data types. They are stored by reference, and
mutable in nature.
The main non-primitive types include:
1. Object – A collection of key-value pairs
2. Array – An ordered collection (technically a special object)
3. Function – A block of reusable code
4. Date, RegExp, Map, Set – Built-in objects
Key Feature: Non-primitive types are mutable, and when you assign them to
another variable, you're copying the reference, not the value.
Q: Can you explain the difference between var, let, and const in
JavaScript in terms of scope, hoisting, redeclaration, and reassignment?
Yes, definitely.
 Scope:
var is function-scoped, while let and const are block-scoped. That means
let and const are only accessible inside the block they’re declared in,
which helps prevent accidental bugs.
 Hoisting:
All three are hoisted, but only var is initialized as undefined. let and const
are hoisted but stay in the temporal dead zone, so accessing them before
declaration gives a ReferenceError.
 Redeclaration:
var allows redeclaration in the same scope. let and const do not —
redeclaring them in the same scope throws a syntax error.
 Reassignment:
var and let allow reassignment. const does not — once assigned, you can't
change its value. But if it's an object or array, you can still modify its
contents.
So overall, in modern JavaScript, we mostly use let and const, and avoid var
unless necessary for legacy reasons.
Q: What is hoisting in JavaScript?
Hoisting is JavaScript's default behavior of moving variable and function
declarations to the top of their scope during the compile phase.
For example, with var, the variable is hoisted and initialized as undefined, so you
can access it before it's declared — though it’ll be undefined.
With let and const, the declarations are hoisted too, but they aren’t initialized.
Accessing them before the declaration line results in a ReferenceError because
they’re in the temporal dead zone.
So yes — all are hoisted, but they behave differently.
Q: What's the difference between == and === in JavaScript? Can you
explain type coercion as well?
Yes.
== is the loose equality operator. It compares two values for equality after
performing type coercion — that means if the types are different, JavaScript
will try to convert one or both values to the same type before comparing.
On the other hand, === is the strict equality operator. It checks for both
value and type without doing any type conversion. If the types differ, it
immediately returns false.
Q: Can you explain what "Strict Mode" is in JavaScript?
Sure!
Strict Mode in JavaScript is a feature that helps write safer and cleaner code.
When enabled using 'use strict'; at the top of a script or a function, it enforces
stricter parsing and error handling.
For example, it doesn’t allow the use of undeclared variables, which helps catch
bugs early. It also prevents some silent errors from going unnoticed — like
assigning to a non-writable property or using duplicate function parameters.
Another key thing is that in normal mode, this inside a function defaults to the
global object, but in strict mode, this will be undefined, which avoids unintended
behavior.
Overall, I’d say strict mode makes your code more predictable and easier to
debug, especially in large projects.
Q: Can you tell me what Built-in Methods are in JavaScript, and also
explain standard naming conventions?
Yes, absolutely.
Built-in Methods in JavaScript are functions that are already provided by
JavaScript’s built-in objects like String, Array, Math, Date, and so on. These
methods help perform common tasks without us having to write logic from
scratch.
For example:
 [Link]() — converts a string to uppercase.
 [Link]() — adds an element to the end of an array.
 [Link]() — returns a random number between 0 and 1.
 [Link]() — gives the current timestamp.
They save time and make the code cleaner.
As for Naming Conventions:
JavaScript follows some common conventions for better readability and
maintainability:
 camelCase for variables and functions.
Example: let userName = "Jayesh";, function fetchData() {}
 PascalCase for constructor functions and classes.
Example: class UserProfile {}
 UPPER_CASE for constants (especially those that don't change).
Example: const MAX_LIMIT = 100;
Following these naming styles makes the code more readable and consistent
across teams.
Q: Can you explain what a function is in JavaScript?
Yes.
A function in JavaScript is a reusable block of code designed to perform a specific
task. Functions help organize code, reduce repetition, and improve readability.
There are different ways to declare functions — like function declarations,
function expressions, and arrow functions.
Example:
js
CopyEdit
function greet(name) {
return "Hello, " + name;
}

Q: What's the difference between function declaration and function


expression?
A function declaration is hoisted, meaning you can call it before it’s defined in
the code.
A function expression is not hoisted — it only works after the line it's defined.
Example:
sayHello(); // ✅ works

function sayHello() {
[Link]("Hi");
}

// vs

const greet = function () {


[Link]("Hello");
};
greet(); // ✅ works only after this line

Q: What are objects in JavaScript?


Objects are key-value pair collections used to store related data and functions.
They are one of the most important non-primitive data types in JavaScript.
Example:
js
CopyEdit
const user = {
name: "Jayesh",
age: 22,
greet: function () {
[Link]("Hello, I'm " + [Link]);
}
};
Objects can also store arrays, nested objects, and methods.

Q: Can you explain Scope in JavaScript?


Sure.
Scope refers to the accessibility or visibility of variables. In JavaScript, there are
three main types:
1. Global Scope – variables accessible anywhere in the code.
2. Function Scope – variables declared with var inside a function are
accessible only within that function.
3. Block Scope – variables declared with let and const inside {} blocks are
only accessible within that block.
Understanding scope is crucial for managing variable lifetimes and avoiding bugs
like variable collisions.

What are Higher-Order Functions in JavaScript?


A Higher-Order Function is a function that either takes another function as an
argument, returns a function, or does both.
In JavaScript, functions are treated as "first-class citizens", meaning they can be
passed around just like values — which makes higher-order functions possible.
What are the different methods of creating objects in JavaScript?
JavaScript provides several ways to create objects, depending on the use case.
Here are the main ones:
1. Object Literal (Most common)
This is the simplest and most direct way.
2. Using new Object() Constructor
This uses the built-in Object constructor.
3. Constructor Function
You can define your own constructor and use the new keyword.
4. [Link]() Method
This allows you to create an object with a specified prototype
5. ES6 Classes
A modern and cleaner way using class syntax.
What are the key differences between JavaScript and Java?
Sure.
JavaScript is mainly used for web development — it's interpreted, dynamically
typed, and runs in the browser (or with [Link]). It supports prototype-
based and functional programming.
Java, on the other hand, is a compiled, statically typed, class-based language
that runs on the JVM. It's used for building large-scale applications like Android
apps, enterprise software, and backend systems.
So, even though the names sound similar, the languages are quite different in
usage, design, and execution model.

You might also like