JavaScript Basics: Easy Explanation
What is JavaScript?
JavaScript is a programming language used to make web pages interactive (like buttons,
forms, animations, etc.). It runs in the browser.
What is advantage of JavaScript?
- Runs in browser (no need for server for basic tasks)
- Makes websites interactive
- Easy to learn
- Supports event-based and object-oriented programming
- Used in both frontend and backend ([Link])
What is client side rendering?
Client-side rendering means the browser (client) loads content and renders it using
JavaScript, instead of loading full pages from the server.
Who invented JavaScript?
Brendan Eich invented JavaScript in 1995 while working at Netscape.
What are features of JavaScript?
- Lightweight
- Dynamic typing
- First-class functions
- Platform independent
- Event-driven
- Interpreted language
What is a variable?
A variable is a container used to store data like numbers, strings, etc.
What are ways to create a variable in js?
- var
- let
- const
What are the datatype in js?
- Primitive: Number, String, Boolean, Null, Undefined, BigInt, Symbol
- Non-Primitive: Object, Array, Function
What is number datatype?
It represents both integers and floating point numbers. Example: let x = 42;
What is string datatype?
A string is a sequence of text characters. Example: let name = "Harish";
What is boolean datatype?
It represents either true or false. Example: let isOn = true;
What is null datatype?
null means no value or empty value (manually set).
What is undefined datatype?
undefined means a variable has been declared but no value is assigned.
What is difference between null and undefined?
Null: manually set to empty value.
Undefined: automatically set when variable is declared but not assigned.
What is BigInt datatype in js?
Used to store very large integers beyond Number limit. Example: let big =
12345678901234567890n;
What is var keyword?
- Declares a variable
- Function-scoped
- Can be redeclared
- Hoisted to the top
What is let keyword?
- Block-scoped
- Cannot be redeclared in same block
- Hoisted (but not initialized)
What is const keyword?
- Block-scoped
- Cannot be redeclared or reassigned
- Must be initialized at declaration
What is difference between let and var keyword?
let is block scoped and safer.
var is function scoped and can be redeclared.
What is NaN property in JavaScript?
NaN = Not a Number. It shows up when you try to do math with non-numeric values.
What would be the result of 1+2+'3'?
Result: '33'. First 1 + 2 = 3, then 3 + '3' = '33' (string).
What is typeof operator?
typeof checks the data type of a variable. Example: typeof 'Hello' → 'string'
What is the difference between == and ===?
== compares value only. === compares value and type.
What are output statements in js?
- [Link](): prints to console
- alert(): popup message
- [Link](): writes to HTML
What is input statement in js?
Used to take input from user using prompt().
What is alert() in js?
Shows a popup message to the user. Example: alert('Hello!');
What is default return type of prompt?
Always returns string. Example: typeof prompt('Enter name') → 'string'