Learning javascript through this series and further making projects
Datatypes are of 2 types:
- Primitive datatype are datatypes which incude: numbers, strings, boolean null and undefined
- Non Primitive Datatypes which are made from primitive datatypes are: Object which furthur incudes array and function.
- interconversion of datatypes
In this video we learn about memory allocation in js.
In this we study that there are two types of process :
- Stack: for PRIMITIVE DATA TYPES
- Heap: for NON PRIMTIVE DATA TYPES.
Difference between Stack and Heap
| Points of difference | STACK | HEAP |
|---|---|---|
| style of data storing | copying | reference |
| updates the original data | NO | YES |
Call By Reference : WHEN I AM CHANGING THE AGE OF USERTWO AND PRINTING THE VALUE OF USERONE HOW THE VALUE OF USERONE IS CHANGING THIS IS CALLED CALL BY REFERENCE.
Strings are primitive datatypes.
To learn string the best is to learn string methods the best method are on MDN REFERENCE.
Some Methods are:
This is the code to Numbers and Maths
In this video we learn about function of number and maths.
Some important functions are:
- Math.random()
- Math.round(number_to_be_rounded)
- Math.floor(number)
- Math.ceil(number)
I WANT A RANDOM NUMBER BETWEEN 10-20;
- javascript
const min = 10;
const max = 20;
console.log(Math.round(Math.random()*(max-min+1)+min));
In this game user has to guess a number between 1-100. We use the following:
- In this game we use number property like
- Math.random()
- Math.round()
- Also we use " === " to compare userNumber and computerNumber.
- " === " is used not " == " to compare both nunmber and type.
In this video we learnt about syntax of array and some methods of arrays.
Array are nothing but non primitive datatypes which are used to structure/stre a data in organised manner.
Array are shallow copies that if you make two arrays equal to each other and you change one of the two array other will be changed automatically this is very similar to CALL BY REFERNCE.
Some important array methods are:
- indexof()
- push()
- pop()
- slice()
- splice()
When i was practicing js on my vs code app i was facing some problem i.e. i was not able to use prompt feature on vs node so i found it difficult to take input.
So while browsing the solution to it i found that i can download a package to make a prompt feature.STEP 1:
- Open PowerShell on your laptop and type
Set-ExecutionPolicy RemoteSignedto give vs code permission to download packages. - TYPE
Y.
STEP 2:
- Open Terminal in your vs code and type
npm install prompt-sync.
STEP 3:
- Write this code in workspace/codespace
javascript
const prompt = require("prompt-sync")();
let userNumber = prompt("enter your number : ");
console.log(userNumber);
Hence you are ready to code and take input in vs code.
[this is code to objects] (./object.js)
it is a way to organise data.
Objects in javascript are of two types:
- Literals,
- Constructor.
In this video we will talk about literals.
Points to Rememmber : When we make an object through literals then the object is singleton.
Two ways to print the elements of the objects:
- 1st way to print thr elements of the objects
console.log(studentDetails.rollNumber); - 2nd way to print the elements of the object(Preferred and correct way)
console.log(studentDetails["subsection"]);
Why 2nd way is preferred because injavascript the object are treated as string so best way is to access it as strings.
1. hasOwnProperty().
2. freeze().
in this video we learn how to de-structure an object.
It is very difficult and impractical to writeconsole.log(studentDetails.rollNumber)
again and again so as an easy transformation we write it once as this
const {rollNumber} = studentDetails
and now we can print by only writing
rollNumber.
Also if i want short name for rollNumber i can write it as
const {rollNumber: roll} = studentDetails
and now i can just write roll for printing roll number.
Function are package which once defined can be used anywhere in the program.
It involves three steps that is
-
Function Definition: In this we give the function what it has to perform.
-
Function Call: In this we instruct a function to execute a block of code.
-
Function Execution: In this the code finally executes.
function addTwoNumber(a, b){ Here a and b are parameters
return a+b;
}
addTwoNumber(1, 6) 1 and 6 are arguments.
console.log(addTwoNumber(1, 6))
TASK STATEMENT : In this task we have to make a simple message that a user should see after logging In. (GIVE ANY MESSAGE OF YOUR CHOICE. )
Reason for using If statement : so that when the argument is not given it will take undefined by itself so to avoid that if is used it will ask your name in that case.
Also to give default value we can define it along with the parameter.
CLICK FOR SOLUTION.
In this video we learnt about object and array handling with functions.
We were building a shopping cart in this as we donot know number of thing in cart before the shopping so we use REST PARAMETER
There are two type of scope:
-
Global Scope : are the scope which are available throghout the program.
-
Local Scope: are the scope which are available only within a particular function/object.