JavaScript & MEAN Stack Notes
1. MEAN Stack Development Framework
The MEAN Stack stands for MongoDB, [Link], Angular, and [Link]. It is a full-stack
JavaScript framework used to build dynamic web applications:
- MongoDB: NoSQL database that stores data in flexible, JSON-like documents.
- [Link]: Web application framework for [Link], used to build RESTful APIs.
- Angular: Frontend framework developed by Google for building dynamic SPAs (Single Page
Applications).
- [Link]: JavaScript runtime environment that executes code on the server side.
The MEAN stack allows the use of JavaScript throughout the entire development
process—client-side, server-side, and database querying—making development faster and more
consistent.
Architecture Flow:
1. Client (Angular) sends a request.
2. Server (Express + [Link]) handles routing and logic.
3. Database (MongoDB) stores and retrieves data.
4. Response flows back through Express to Angular.
2. Setting Up [Link] and Angular
[Link] Setup:
1. Download and install [Link] from [Link].
2. Verify installation:
node -v
npm -v
JavaScript & MEAN Stack Notes
3. Create a project folder and initialize:
mkdir myproject
cd myproject
npm init -y
Angular Setup:
1. Install Angular CLI globally:
npm install -g @angular/cli
2. Create a new Angular project:
ng new my-angular-app
3. Serve the project:
cd my-angular-app
ng serve
3. JavaScript Variables and Data Types
Variable Declaration: Use var, let, or const.
- var is function-scoped, can be redeclared.
- let and const are block-scoped. const cannot be reassigned.
Example:
let x = 10;
const y = "Hello";
Data Types:
- Primitive: Number, String, Boolean, Null, Undefined, Symbol
- Non-Primitive: Object, Array, Function
JavaScript & MEAN Stack Notes
Example:
let num = 42;
let str = "JS";
let isReady = true;
let arr = [1, 2, 3];
let obj = { name: "Alice", age: 30 };
4. JavaScript Operators
- Arithmetic: +, -, *, /, %, ++, --
- Comparison: ==, ===, !=, !==, <, >, <=, >=
- Logical: &&, ||, !
- Assignment: =, +=, -=, *=, /=
- Bitwise, Ternary, and Type Operators
Example:
let a = 5;
let b = 3;
let max = (a > b) ? a : b;
5. Control Structures
If Statement:
if (a > b) {
[Link]("A is greater");
}
JavaScript & MEAN Stack Notes
Switch Statement:
switch(day) {
case "Mon": [Link]("Start of week"); break;
default: [Link]("Unknown day");
Loops:
for (let i = 0; i < 5; i++) [Link](i);
let j = 0;
while (j < 5) {
[Link](j);
j++;
let k = 0;
do {
[Link](k);
k++;
} while (k < 5);
6. Functions (Parameter Passing & Return Values)
Functions are defined using the function keyword. They can take parameters and return values.
Example:
function add(a, b) {
JavaScript & MEAN Stack Notes
return a + b;
let sum = add(5, 3); // sum = 8
Note: Objects/arrays are passed by reference.
7. Objects (with Examples)
Objects are key-value pairs.
let person = {
name: "Alice",
age: 30
};
[Link]([Link]); // "Alice"
Objects can hold methods:
let car = {
make: "Toyota",
honk: function() {
return "Beep!";
};
8. Strings (Definition, Methods, Programs)
Strings are sequences of characters.
JavaScript & MEAN Stack Notes
Common methods:
length, toUpperCase(), toLowerCase(), substring(), indexOf(), replace()
Example:
let str = "Hello, World!";
[Link]([Link]()); // "HELLO, WORLD!"
Program:
let greeting = "Hello";
let name = "John";
[Link](greeting + " " + name); // "Hello John"
9. Arrays (with Methods and Examples)
Arrays store multiple values.
let colors = ["red", "green", "blue"];
[Link]("yellow"); // ["red", "green", "blue", "yellow"]
Useful methods:
push(), pop(), shift(), unshift(), splice(), slice(), forEach(), map()
Program:
let nums = [1, 2, 3];
let doubled = [Link](n => n * 2); // [2, 4, 6]
10. Error Handling (try, catch, finally)
JavaScript & MEAN Stack Notes
JavaScript uses try-catch-finally for error handling.
Example:
try {
throw new Error("Something went wrong");
} catch (err) {
[Link]([Link]);
} finally {
[Link]("Cleanup done");
11. NPM Command-Line Options (Table 3.1)
Common NPM Commands:
- npm install
- npm update
- npm uninstall
- npm init
- npm run
Options:
--save: adds to dependencies
--global: install globally
Example:
npm install express --save
JavaScript & MEAN Stack Notes
12. [Link] Directives (Table 3.2)
Key directives:
- name, version, description, main, scripts, dependencies, devDependencies
Example:
"name": "myapp",
"version": "1.0.0",
"scripts": {
"start": "node [Link]"
13. Writing Data to Console (with Examples)
Use [Link]() to print data.
Other methods:
- [Link]()
- [Link]()
- [Link]()
- [Link]()
Example:
[Link]("Hello, World!");
[Link]("This is an error");