Clarification on Javascript scope while object creation and prototype

5 views
Skip to first unread message

VikramSrinivasan Venkatakrishnan

unread,
Mar 5, 2017, 5:55:21 PM3/5/17
to JPassion.com: JavaScript Programming
Hi Sang, 

I have few questions on couple of slides in the java script video. I have explained my questions in detail in the attached document with screen shots. I will really appreciate if you take some time and clarify them. Thanks again for all your help.

Thanks,
Vikram
Javascript_clarifications.docx

Sang Shin

unread,
Mar 6, 2017, 11:22:29 AM3/6/17
to jpassion_...@googlegroups.com

In the future, it will help me and others in this alias to answer your question better if you
post a single question per email preferably with text and attached
images.

I will try to answer the first question.  And if you can post the second question
as I suggested above, that will be appreciated

- The scope of a variable is only relevant regarding a function
- In JavaScript, an object is defined as key value pairs
- The following is a valid syntax as an object
 

var hash_fnc = {

             a : 10,

             b : 15,

             c : function add(a, b){

                console.log(a+b);

            } 

        }


-But the following is not a valid syntax because
you cannot use var inside an object, you use it
inside a function.

var hash_fnc = {

          var a : 10,

             b : 15,

             c : function add(a, b){

                console.log(a+b);

            } 

        }


-- 
-------------------------------------------------------------------
             Sang Shin, sangshi...@gmail.com
         http://www.linkedin.com/in/javapassion (Linkedin)
          http://twitter.com/javapassion (Tweeter)
            Life is worth living... with Passion!
----------------------------------------------------------------------
Reply all
Reply to author
Forward
0 new messages