Lets begin with some highlevel JavaScript basics :)…

Java script simple statements could be ended without semi colon

Statements:

Both the below statements are valid

var a= 6;
var a=5

you could use ‘;’ semicolon to write multiple statement in single line

var1 =10;var 2=23;var 5= 9

Java script is case sensitive, meaning ‘Time’ and ‘time’ are two different elements.

Comments:

//single line comment
/* multi line statement
can be made like this */

html comment closing ‘ → ‘ is not detected by Javascript

Data Types:

Primitive:

JS following primitive data types:

  • Numbers — 1,2,3 ( Java script does not have separate representation for floating point and whole numbers, all the numeric are represented as floating points (Eg: 2.0)
  • Strings — “name”
  • Boolean — true or false

also supports ‘null’ and ‘undefined

Composite

JS also so support data type called ‘object

Declaring variables:

Variables are elements that store data and helps in re-usability

In JS , variables needs to be declared before it could be used. In JS , variable declaration could be made mainly using three keywords and are :

  1. var
  2. let
  3. const

Note: JS is dynamically typed (untyped) , meaning data type is detected dynamically. For instance, if for below variables , we store username = 1 and password = “we”; then the data type of username will be taken as Number and password as string.

Using Var

var username
var password

Multiple variable declaration in a single line is also permitted

var username,password,url

Note:

  • Variables declared with var are function scoped.
  • Could be modified
  • Could be re-declared ( It will replace the previous variable)
  • Does support hoisting (meaning that , if the variable is called before declaring , then JS will automatically declare and initialize it with value ‘undefined’)
console.log(username)
var username = "user"
// This prints "undefined" because java script changes this code internally as 
var username = undefined
console.log(username)
username = "user"
//This is called hoisting

Using let:

let username;

Note:

  • Variables declared with let are block scoped.
  • Could be modified
  • Could not be re-declared ( It will replace the previous variable)
  • Does not support hoisting. Variable should be declared before it could be used

Using const:

const username;

Note:

  • Variables declared with const are block scoped.
  • Could not be modified
  • Could not be re-declared ( It will replace the previous variable)
  • Does not support hoisting. Variable should be declared before it could be used

To know more read : ( Read : https://medium.com/@toddhd/javascript-understanding-the-difference-between-var-let-and-const-d0390da913 )

Variable Scope:

JavaScript only two scope :

  • Global — Available anywhere in the code
  • Local — Available only to the local function in which its defined

Variable naming rules:

Operators in JavaScript:

  • Arithmetic Operators

+ , — , * , / ,% , ++, —

  • Comparison Operators

==, !=, > , <, >=, <=,

  • Logical (or Relational) Operators

&& (AND) , || (OR), !

  • Assignment Operators

=, += (add and assign), -=, *= ,/=, %=

  • Conditional (or ternary) Operators

?:

eg: a==b? true:false

  • Bitwise Operators

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.