Table of contents
- đź”—Reference - JS Cheat Sheet
- Q1. What is the difference between a compiled language and an interpreted language?
- Q2. Why we need a programming language ?
- Q. 3 JavaScript is a versatile and widely-used programming language primarily known for its role in web development. Here are key aspects of JavaScript:
- Q.4 Why we need ECMAScript ?
- Q.5 Why most of the programming language are case-sensitive ?
- Q6. Variable Declaration and Initialization.
- Topic: JS - Operators
<!-- Linking an external JavaScript file -->
<script src="path/to/your/script.js"></script>
đź”—Reference - JS Cheat Sheet
Q1. What is the difference between a compiled language and an interpreted language?
Answer:
Compiled Language:
Code needs to be translated into machine code before execution.
The entire program is converted into machine code at once, creating an executable file.
Examples include C, C++, and Java (to some extent).
Interpreted Language:
Code is executed line by line or statement by statement.
No separate compilation step; the interpreter translates the code at runtime.
Examples include Python, JavaScript, and Ruby.
Q2. Why we need a programming language ?
Answer:
Programming languages are necessary for humans to communicate instructions to computers in a way that is readable and understandable.
They provide a level of abstraction, allowing developers to express complex algorithms efficiently. Programming languages enhance productivity, enable automation, and support innovation by providing a structured and standardized approach to problem-solving. They are essential for creating diverse software applications, from web development to artificial intelligence, and play a crucial role in computer science education.
Q. 3 JavaScript is a versatile and widely-used programming language primarily known for its role in web development. Here are key aspects of JavaScript:
Client-Side Scripting:
- JavaScript is mainly used as a client-side scripting language, running in web browsers to enhance interactivity and provide dynamic content on websites.
High-Level and Interpreted:
It's a high-level language, meaning it has abstraction from the machine-level details.
Interpreted at runtime, allowing developers to execute code without a separate compilation step.
Object-Oriented:
- JavaScript follows an object-oriented programming paradigm, using objects and prototypes for building reusable and modular code.
Event-Driven:
- JavaScript is event-driven, responding to user actions like clicks and keyboard inputs. This capability makes web pages interactive.
Cross-Platform:
- Executed by web browsers on various platforms, making it a cross-platform language.
Asynchronous Programming:
- Supports asynchronous programming through features like callbacks and Promises, crucial for handling tasks without blocking the main execution thread.
DOM Manipulation:
- JavaScript interacts with the Document Object Model (DOM) to dynamically update the content and structure of web pages.
Versatile Usage:
- Beyond web development, JavaScript is used in various environments, including server-side development (Node.js), mobile app development (React Native, Ionic), and even in game development.
Libraries and Frameworks:
- Numerous libraries (e.g., jQuery) and frameworks (e.g., React, Angular, Vue) are built on top of JavaScript, simplifying common tasks and promoting efficient development.
ECMAScript Standard:
- JavaScript adheres to the ECMAScript standard, which defines the scripting language specification. Various versions, such as ES5, ES6 (ES2015), and subsequent updates, introduce new features and improvements.
Q.4 Why we need ECMAScript ?
ECMAScript is like a rulebook for JavaScript. It gives a set of guidelines that all JavaScript implementations should follow. This helps make sure that code works consistently across different browsers and platforms. It also allows developers to use the latest features and keeps the JavaScript language up-to-date. Following ECMAScript standards is like speaking a common language in the programming world, making it easier for developers to work together and build reliable and compatible web applications.
Q.5 Why most of the programming language are case-sensitive ?
The case sensitivity of programming languages is often rooted in the underlying ASCII (American Standard Code for Information Interchange) or Unicode character encoding systems. ASCII assigns distinct numerical values to uppercase and lowercase letters. Let's look at why programming languages are case sensitive in terms of ASCII values:
ASCII Values:
ASCII assigns unique numeric values to each character, including uppercase and lowercase letters. For example:
Uppercase 'A' has ASCII value 65.
Lowercase 'a' has ASCII value 97.
The difference between uppercase and lowercase letters is 32 (97 - 65).
Binary Representation:
- Computers represent characters in memory using binary code, and the difference between uppercase and lowercase letters is reflected in the binary representation. The most significant bit (MSB) is often used to distinguish between uppercase and lowercase.
Type | Representation | ASCII Range |
Integer | '0' to '9' | 48 to 57 |
CAPITAL ALPHABET | 'A' to 'Z' | 65 to 90 |
String | 'a' to 'z' | 97 to 122 |
Q6. Variable Declaration and Initialization.
keyword | variable_name (container) | assignmentalOperator | value |
var | age | \= | 15 |
var - global variable | |||
let - local variable | |||
const - local variable | firstName _counter $totalAmount user123 calculateTotal | assigning value from its right side to its left side | Value or Data |
Keyword
| Keyword | Scope | Hoisting | Reassignment | Example | | --- | --- | --- | --- | --- | |
var
| Function | Hoisted and | Can be |javascript function example() { if (true) { var x = 10; } console.log(x); // 10 (hoisted to the function scope) }
| | | | initialized | reassigned | | |let
| Block | Hoisted but | Can be |javascript function example() { if (true) { let y = 20; } console.log(y); // ReferenceError: y is not defined }
| | | | not initialized | reassigned | | |const
| Block | Hoisted but | Cannot be |javascript const z = 30; z = 40; // Error: Assignment to constant variable
| | | | not initialized | reassigned | |
my-variable (contains a hyphen)
my variable (contains a space)
if (reserved keyword) | |
1. Primitive Data Type
number - 12,-12, -15.5,
boolean true/false
string- "abc" / 'abcd' | | | | | undefined-undefined | | | | | object - null symbol | | | snake_case_pattern camelCasePattern PascalCasePattern | |
2. Non-Primitive Data Types
or Reference Data Types
object(array,object,function) |
Topic: JS - Operators
// ---------- JS - OPERAOTRS
// 1. Arithemetic Operators
// +, -, *, /, %, ** (binary operator)
// ++, -- (unary operator -> increment/decrement)
let res;
let a = 12;
// res = a++;
// res = ++a;
// res = --a;
// res = a--;
res = ++a + a++ - a-- + --a + a;
// res -> 13 + 13 - 14 + 12 - 12
// a -> 12 13 14 13 12
// console.log(a);
// console.log(res);
// 2. ASSIGNMENT OPERATORS
// +=,-=,*=,/=,%=,**= (compound assignment operators)
// a = b
// a += b
// a -= b
// a *= b
// a /= b
// a %= b
// a **= b
// 3. Comparison Operator (always return boolean value)
// > < >= <= == === != !==
// console.log(12 > 5);
// console.log(12 == '12');
// console.log(12 === '12');
// console.log(12 != 12);
// console.log(12 !== '12');
// 4. Logical Operators (returns a/c to datatypes comparison)
// examples of logical operator are:
// && || (binary)
// ! (unary) -> always return boolean value
// console.log(!true);
// falsy value: 0, "" , null, undefined, NaN, false
// truthy value: any non-falsy value
// console.log(true);
// console.log(!true);
// console.log(!!true);
// console.log(0);
// console.log(!0);
// console.log(!!0);
// console.log(!!12); // converting any datatype into boolean
// console.log(undefined);
// console.log(null);
// console.log(!null);
// console.log(!!null);
// console.log(false || true);
// console.log(false && true);
// console.log(false && true);
// console.log(12 && 16);
// console.log(12 || 16);
// console.log(12 && '16');
// console.log(12 || '16');
// console.log(null || '12');
// console.log('12' || null);
// console.log(null && '12');
// console.log('12' && null);
// console.log(null && 'ayu');
// console.log('ayu' && null);
let c = 33;
// console.log(c > 20);
// console.log(c % 2 === 0);
// console.log(c > 20 || c % 2 === 0);
// console.log(c > 20 && c % 2 === 0);
// console.log(c > 20 && c % 2 === 0);
let res2 = c > 15;
// res2 && console.log(c);
res2 || console.log(c);
JavaScript mein "operator" ek prakar ka symbol ya keyword hota hai, jo ki various operations ko perform karne mein madad karta hai. Operators values, variables, ya expressions ke beech mein various operations jaise ki arithmetic, comparison, assignment, logical, etc., execute karne ke liye use hote hain.