Skip to content

prathamk108/javascript-by-chai-and-code

Repository files navigation

javascript-by-chai-and-code

Learning javascript through this series and further making projects

Basics

Datatypes

Datatypes are of 2 types:

  1. Primitive datatype are datatypes which incude: numbers, strings, boolean null and undefined
  2. Non Primitive Datatypes which are made from primitive datatypes are: Object which furthur incudes array and function.
  3. interconversion of datatypes

Video 10: Memory allocation

CLICK THIS TO SEE CODE.

In this video we learn about memory allocation in js.

In this we study that there are two types of process :

  1. Stack: for PRIMITIVE DATA TYPES
  2. 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.

Video 11: Strings

This is the code to strings.

Strings are primitive datatypes.

To learn string the best is to learn string methods the best method are on MDN REFERENCE.

Some Methods are:

  1. toUpperCase().
  2. toLowerCase().
  3. slice().
  4. split().

Video 12: Numbers and Maths

This is the code to Numbers and Maths

In this video we learn about function of number and maths.

Some important functions are:

  1. Math.random()
  2. Math.round(number_to_be_rounded)
  3. Math.floor(number)
  4. 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));

Number Guessing Game (Project 1):

This is Game Code.

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.

Video 14 : Arrays and Array Methods

This is array code.

In this video we learnt about syntax of array and some methods of arrays.

What are 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.

ARRAY METHODS

Some important array methods are:

  1. indexof()
  2. push()
  3. pop()
  4. slice()
  5. splice()

Something Important for Beginners

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.

SOLUTION:

STEP 1:

  1. Open PowerShell on your laptop and type Set-ExecutionPolicy RemoteSigned to give vs code permission to download packages.
  2. TYPE Y.

STEP 2:

  1. Open Terminal in your vs code and type npm install prompt-sync.

STEP 3:

  1. 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.

Video 16 : OBJECTS

[this is code to objects] (./object.js)

What are objects?

it is a way to organise data.

Objects in javascript are of two types:

  1. Literals,
  2. 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:

  1. 1st way to print thr elements of the objects console.log(studentDetails.rollNumber);
  2. 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.

Object Methods

1. hasOwnProperty().
2. freeze().

Video 18: Object De-Structuring and JSON


FOR REFERENCE CLICK HERE.

in this video we learn how to de-structure an object.

It is very difficult and impractical to write

console.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.

Video 19: Functions

CLICK HERE FOR REFERENCE.

What are Functions??

Function are package which once defined can be used anywhere in the program.

How can you use a Function??

It involves three steps that is

  1. Function Definition: In this we give the function what it has to perform.

  2. Function Call: In this we instruct a function to execute a block of code.

  3. Function Execution: In this the code finally executes.

Some terminologies used in Functions(FOR INTERVIEW PURPOSE)

1. Parameters: are variables defined in function definition step. 2. Arguments: are the constants defined in function calling steps.
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))

FUNCTION: TASK 1

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. )

CLICK FOR SOLUTION.

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.

Video 20 : Function with Array and Object.

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

Video 21: Scope

THIS IS CODE.

TYPE OF SCOPE

There are two type of scope:

  1. Global Scope : are the scope which are available throghout the program.

  2. Local Scope: are the scope which are available only within a particular function/object.

Video 21: Scope Level and Hoisting

About

Learning javascript through this series and further making projects

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors