Skip to content

Commit c27a295

Browse files
committed
foundation 1 and 2 notes
0 parents  commit c27a295

File tree

3 files changed

+128
-0
lines changed

3 files changed

+128
-0
lines changed

js_notes/foundation1.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/* Foundations of js - 01 -> PRIME FOCUS = basics of variables and datatypes*/
2+
3+
/*
4+
1.What are value
5+
2.What is a variable
6+
3.what are datatypes
7+
4.what are 7 primitive datatypes
8+
5.3 ways to Declare a variable in js - let,const,var
9+
6.console.log function
10+
7.Type of operator
11+
8.Whats Dynamic typing & its action
12+
9.Comments in JS
13+
*/
14+
15+
// 1. What are values - its a piece of data - 13 , 12.89 , true , 'Indresh' etc
16+
17+
// 2. What is a variable - All tasks in software deals with data and thus it is essential to store it. Variables are containers that can store values/data
18+
19+
// 3. What is a datatype - values can be of different types. These are called datatypes. In JS values are of broadly 2 types -> primitive datatypes and objects
20+
21+
// 4. what are 7 primitive datatypes
22+
/*
23+
-> Numbers = both int and floats
24+
-> String = Sequence of characters in quotes
25+
-> Boolean = logical datatype whose values are - true or false
26+
-> undefined = means empty value & If a variable is declared and not yet initialised it takes up this datatype as default
27+
-> null = indicates empty/no value and is a assigned value intentionally
28+
-> Bigint = ES2020 feature - stores large numbers
29+
-> Symbol = ES2015 feature - represents values that are unique and cant be changed
30+
*/
31+
32+
// 5. Declaring and initialising a variable
33+
/* declaring Syntax-> keyword variablename ;
34+
initialising Synatx -> variablename = value;
35+
36+
There are 3 keywords to declare a variable
37+
1.let keyword -> used to declare those variables whose values may be mutated in future
38+
2.const keyword -> used to declare those variables whose values are not going to be changed/reassigned/mutated
39+
3.var keyword -> shd be completely avoided after ES6
40+
*/
41+
let num1; //declaring
42+
num1 = 10; //initialising
43+
let num2 = 12; //declaring and initialing at the same time
44+
num1 = 15; //reassigning/mutating/changing the value of variable num1
45+
46+
const fullname = "Indresh"; //declaring and initialising shd be done at the same time for const keyword
47+
//const class; This gives error becz const variables cant be left without initialising
48+
//Its preffered to keep most of your code in const if you are sure its not going to be mutated
49+
50+
var a;
51+
a = 10;
52+
var b = 12;
53+
//by this we see var is similar to let but there are some differences ->
54+
/*Variables declared by let are only available inside the block where they're defined. Variables declared by var are available throughout the function in which they're declared*/
55+
56+
// 6. console.log function
57+
/*
58+
-> It is a built-in function in js which when called prints/logs the contents in the console of the browser
59+
*/
60+
console.log("Welcome javascript"); //logging a string
61+
console.log(num1); //logging a variable
62+
console.log(12); //logging a number
63+
console.log(15 + 6); //logging an expression
64+
console.log("hello " + fullname); //logging a concatenated string and variable
65+
66+
// 7. Typeof operator
67+
68+
//It tells us the datatype of a value/variable
69+
console.log(typeof num1);
70+
console.log(typeof fullname);
71+
console.log(typeof true);
72+
let x;
73+
console.log(typeof x); // uninitialised variable - undefined datatype
74+
let y = null;
75+
console.log(typeof y); // gives output as object which is a bug and not resolved for legacy reason
76+
77+
// 8. Dynamic typing in javascript
78+
/*
79+
This means we dont havre to manually define the datatype of the value which the variable can store.
80+
a variable can have any value belonging to any datatype
81+
*/
82+
let dynamic = 10; //dynamic holds a num
83+
dynamic = true; //dynamic holds a boolean
84+
dynamic = "hello JS"; //dynamic holds a string
85+
86+
// 9. Comments in JS
87+
88+
/* multiline comment */
89+
// single line comment

js_notes/foundation2.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/* Foundations of js - 02 -> PRIME FOCUS = everything needed for Logical statements */
2+
3+
/*
4+
1.What are statements and expressions
5+
2.What is a operator and a operand -> operator precendence
6+
3.Concatenation of string by + operator & template literals
7+
4.Multiline strings before ES6 and after ES6
8+
5.Conditional if-else statement
9+
6.Type conversion and type coercion in numbers , strings and boolean
10+
7.Equality operators (== vs ===)
11+
8.Inequality operators (!= vs !==)
12+
9.Switch statements in JS
13+
10.Conditional / terenary operator
14+
*/
15+
16+
// 1. What is statements and expression
17+
/*
18+
Expression is a piece of code that is a value or produces/outputs a value
19+
3+4 , 15 , true && false , 23 > 13 , "hello" -> all these are values or gives a value after solving
20+
21+
Statements is a piece of code that gives instructions and is executed but it doesnt hold any value of its own
22+
Many expressions combine to form a statement and they end with ;
23+
*/
24+
25+
if (23 > 13) {
26+
// this is a statement as whole, 23>13 is expression having a value of true
27+
console.log("23 is greater than 13"); // this is a statement & the value inside console.log is an expression
28+
}
29+
30+
//The main reason to understad statemnenst and expressions is because JS expects an expression at a place where a value is expected and statements at a place where a value is not expected.
31+
32+
//2. What is operator and operand
33+
34+
//let us take an expression ->
35+
2 + 5; //2,5 -> operand , + -> operator , 7 is the value of expression
36+
true && false; //true,false -> operand , && -> operator , false is the value of expression
37+
"hello" + "world"; //"hello" , "world" -> operand , + -> operator , "helloworld" is the value of expression
38+

js_notes/note.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
js

0 commit comments

Comments
 (0)