Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7959503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:35:03+00:00 2026-06-04T04:35:03+00:00

For using a static variable in javascript functions I found out two ways, using

  • 0

For using a static variable in javascript functions I found out two ways, using . and : operator.
When using . operator we have to specify variable with “f.variable” and when using : we have to use “this.variable”. what is the difference between the usage of these two operators.

function f(){
  f.a += 1;
  this.b += 1;
  console.log("f.a: ", f.a);
  console.log("this.b: ", this.b);
}
f.a = 0;
f:b = 0;

also we cannot use : when using that variable outside its function like:

function g(){
  f:b = 0; //this works fine.
  var c = f:b; //raises error invalid label.
  console.log(f:b);//but this raises an error missing ')'.
}

Same is the case when we use var to create objects.

var obj = {
 a: 2,
 b: 3
}
//accessing a and b is done using obj.a & obj.b
//but here
obj:a = 4;
console.log(f.a); // this gives 2
//and similarly using obj:a as rhs value gives error.

How are these two operators used actually.

EDIT:
What is the difference between these two types of variables created.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:35:03+00:00Added an answer on June 4, 2026 at 4:35 am

    This:

    f:b = 0;
    

    is interpreted as a label, “f”, before an expression statement, b = 0;. The “:” is used in object literal syntax to separate a property name expression from its value expression. Otherwise, it is not used for referring to properties of objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a way, using static analysis of two JavaScript functions, to
How to implement singleton without using static/global variable? Possible? This is an interview question...
Fairly simple issue which is solved in PHP by using a static variable. private
I have been reading that creating dependencies by using static classes/singletons in code, is
I just learned this way of initializing a variable in javascript: var MyGlobalVar =
i have a full static class, using a std::map thats the simplified case .h
I am trying to access a static variable within a class by using a
I have the following code that gets initialized as a static variable in a
In android, are using static variables a recommended practice? E.g, implementing a Singleton pattern
How to share data between different threads In C# without using the static variables?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.