Apply for Zend Framework Certification Training

Javascript





What is javascript

 

                       

Assignments 

Create an Add address form using DOM

What is javascript

JavaScript is a scripting or programming language that allows you to implement complex features on web pages — every time a web page does more than just sit there and display static information for you to look at — displaying timely content updates, interactive maps, animated 2D/3D graphics, scrolling video jukeboxes, etc. — you can bet that JavaScript is probably involved. It is the third layer of the layer cake of standard web technologies, two of which (HTML and CSS) we have covered in much more detail in other parts of the Learning Area.

JavaScript Variables

Variables are Containers for Storing Data

JavaScript Variables can be declared in 4 ways:

 

1)Automatically

2)Using var

3)Using let

4)Using const

When to Use var, let, or const?

1. Always declare variables

2. Always use const if the value should not be changed

3. Always use const if the type should not be changed (Arrays and Objects)

4. Only use let if you can't use const

5. Only use var if you MUST support old browsers.

Js output

<script>

    var a = 10;

    console.log(a);

    var a = "Satish";

    console.log(a)

 

    Types of variable

    var,let,const

 

    b = 20;

    var b = 60;

 

    let c= 30;

    console.log(c)

    c= 45;

    console.log(c)


 

    const d = 66;

    console.log(d)

   // d = 68;

    console.log(d)

 

</script>

Differences between var, let, and const

var

let

const

The scope of a var variable is functional or global scope.

The scope of a let variable is block scope.

The scope of a const variable is block scope.

It can be updated and re-declared in the same scope.

It can be updated but cannot be re-declared in the same scope.

It can neither be updated or re-declared in any scope.

It can be declared without initialization.

It can be declared without initialization.

It cannot be declared without initialization.

It can be accessed without initialization as its default value is “undefined”.

It cannot be accessed without initialization otherwise it will give ‘referenceError’.

It cannot be accessed without initialization, as it cannot be declared without initialization.

These variables are hoisted.

These variables are hoisted but stay in the temporal dead zone until the initialization.

These variables are hoisted but stays in the temporal dead zone until the initialization.



 

‘use strict’;

This keyword is used to strictly follow the variable declaration before using it

Eg:-

'use strict';

x= 10;

console.log(x);

Error will be  ReferenceError: x is not defined  

Variable Hoisting

It means a variable will not be used before declaration

x= 10;

console.log(x);

let x;

 

< First Getting Started With CodeIgniter URL Routing >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top