What i learnt about JavaScript in a week. #1
Hey! i am Prakash and today i am going to share my experience with JavaScript in my first 7 days of learning. I am going to make this Post short like TL;DR and make it like Cheat Sheet that is understandable for beginners with little bit knowledge like me.
In this this part i am going to talk about Variables, Operators, and Objects.
Variables :
Variable is like dish that you need every time you eat something yeah i know its a silly example. okay now just understand this few things about Variables :
- Variable is used to store data temporarily in the system memory. var is assigned /reserved keyword.
- You should give variable a name to Recognize it later. Example //var myName = ‘prakash’; // here ‘myName’ is name, ‘=’ is assigned operator and ‘prakash’ is value.
- JavaScript is Dynamic Language so it would automatically recognize the value type (such as String, Number, Boolean ..etc.)
- There are few Rules that you should follow while giving a name to variable :
- a) the name cannot be same as Reserved Keywords(like var,this, const,let,if … etc, do Research on Reserved words.).
- b) you cannot start a variable name with a number.(var 1name; // just don’t do this.) and also don’t use any space or slash symbol( — ) it’s not allowed.(var java script; or var java-script //wrong way !).
- c) var names are Case Sensitive. (var jaVasCript; and var javaScript; will display as different variables).
- d) this thing you can do or i say you must DO, use Camel Notation (yes something we can do), Camel Notation is a best practice to give names in JavaScript (Examples : var javaScript; var myFirstName; var goodMorningNewYork;).
- After ES5, Variables has two types : a) const and b) let ,
- a) const is used for the value that is constant we we don’t have any intention to change that in future.
- b) let is used for changeable values in JavaScript.
Operators :
Quick Notes about operators , just remember two types of Operators : a)Binary and b) Unary.
- a) Binary needs two Operands and one Operator to perform operation.(example: a * b; 5 + 6 = 11; here a,b,5 and 6 are Oprands and ‘*’ and ‘+’ are Operators.)
- b) Unary needs one Oprand and two Operator.(Example:y++; ++x;).
Objects:
Everything Consist a value is an Objects( If they are not Primitive but even Primitives acts like objects). but we are not gonna Escape Primitives so here are types of Primitive :
- String: is any value between quotation marks. ( “hey”, ’123’ “1one”)
- Boolean: true or false.(var aboveAdultAge = true;)
- Number: use numbers without quotations. (Var length= 10; var width=20;)
- Undefined: not defined yet.( Var wait; // if you call this it will show undefined)
- Null: if you set it null means var don’t have any value.
- Symbol: In ES5-6 symbols are introduced. (♥️,🐈,🎂).
Objects are big Deal in JavaScript , as i said Everything that isn’t Primitive are Objects. Functions, Arrays and many more. Here is a catch, two name get changed in Objects , Functions known as Methods and Variables known as Properties in Objects.
Here is the Example of Object superman:
var superMan={ realName: ‘Clark Kent’, powerLimited: false, from: ‘Krypton’, age: 33};
Here are few small things about abovr example that Important to remember otherwise later you will get confuse.
- The Syntax i used in example is Object Literal Notation Syntax.
- realName, powerLimited, from, age are all properties of Object.
- Don’t use semi-colon inside of object. use comma to separate properties.
- Don’t use assigned operator(= ) instead use colon ( : ) .
In next part i am going to cover the rest(about Object Notations, Arrays and Functions) i learnt about JavaScript.
Thanks for reading.