Skip to content

Instantly share code, notes, and snippets.

@r-kohale9
Last active September 8, 2019 16:08
Show Gist options
  • Save r-kohale9/b016cdb2465389f4218c15f4227ba7b7 to your computer and use it in GitHub Desktop.
Save r-kohale9/b016cdb2465389f4218c15f4227ba7b7 to your computer and use it in GitHub Desktop.
JavaScript Notes (Beginners - Mosh)

JavaScript

Companies that use JS -

  • Netflix
  • Walmart
  • Paypal

Average Salary - $72000

JS can be used for Front-end , backend or well full-stack developer. What seperates JavaScript from other languages is that it is a dynamic language.

What can you do?

  1. Web / Mobile .
  2. Real time Networking apps. such as chats or video
  3. Command line tools.
  4. Games.

Where can you run JavaScript code?

  • On browser
  • On Node browser - This means that we can build the backend of our web and mobile applications with JS.

ECMAS script Vs JS

  • ECMAS is a specification.
  • JS is a programing language.

Extensions used ->

  • Live server - lightweight web sever
JavaScript console->
console.log('Hello');
alert('yo');
typeOf name
o/p -> "string"

Setting up development environment.

You don't really need to install seeing as JS can be runned on the browser but we would use nodejs to install 3rd party libraries.

After install Live Server to run the server rt-click on the .html file a click on 'start Live server'.

JavaScript in browser.

To use JavaScript we need to add a script element inside the .html page.

<script>
    console.log('Hello');
</script>

Seperation of concerns

HTML is all about "CONTENT" JS is all about "BEHAVIOUR" What this states is that you should keep ur JS in a seperate file i.e ".js" for e.g "index.js" i.e what ever is in the script tag should be in this file or files.

JavaScript in Node.

To run the JS file with help of Node simply do ->

$ node index.js

Variables (var or let)

By default Variables in JS are intially defined as 'undefined'.

  • Cannot be a reserved keyword
  • Should be meaningful
  • Cannot start with a number (1name)
  • Cannot contain a Space or Hyphen (-)
  • Are case-sensitive
  • The best practice is to have each variable declared and initialised in a different line.
  • Use Pascal notation while declaring variables.

Constants (const)

const - Value remains constant use this when you what don't want the value to change or you should use 'let' seeing as 'var' causes some issues.

Primitive Types

2 types of strings or the values that you can assign to a variable.

  1. Primitives / Value Types.
    • String
    • Number
    • Boolean
    • undefined
    • null e.g:
        let name = 'Rishabh';       // String Literal
        let age = 20;               // Number Literal
        let isApproved = false;     // Boolean Literal
        let firstName = undefined;  // This is by default undefined so theirs really no need to assign 'undefined' to it.
        let selectedcolor = null; 
  2. Referenced Types
    • object
    • Array
    • Function

Dynamic Typing

What seperates JavaScript from other languages is that it is a dynamic language. Their are 2 types of languages-> Static - After declaring a variable the type of the variable can't be changed Dynamic - The type can be changed at run time. Use typeOf to check the type of variable. In JS all number have a type of "number" i.e 30 and 30.0 have a type of number and not float.

'undefined' can be a value as well as type of a variable. 'null' holding variable has a type of 'object'.

Objects.

let person = {
    name = 'R.K',
    age = 20
}
// Dot notation
person.name = 'M.K'
console.log(person.name);

Use the above when you know the name of the property.

// Bracket notation
person['name'] = 'M.K'

Use the above when you don't know the name of the property.

Objects in the array as well as the size of the array or dynamic meaning

let person = ['R.K', 'M.K'];
person[2] = 1;
console.log(person);

In JS arrays have a type 'object'. Whenever a array is declared it inherits a bunch of methods.

Functions

function greet(name, lastName) {
    console.log('Hello' + name + ' ' + 'lastName');
}

let name = 'Rishabh';
let lastName = 'Kohale';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment