Outputting information in Javascript that is not contained within the script itself

Recently, I encountered an issue with my JavaScript code.

var customer = {
    name: "John Jack",
    speak: function(){
        return "my name is "+name;
    },
    address:{
        street: '123 main st',
        city: 'Pittsburgh',
        state: 'PA'
    }
}

document.write(customer.speak());

Expected output in my HTML:

my name is John Jack

However, the actual result was quite unexpected:

my name is Peaks mirroring in a lake below, Stubai Alps, Austria

I have been pondering over various theories as to why this strange output occurred. One suspicion is that it might be related to a Chrome extension I have installed called "Pixlr". But I fail to see how my JS code could be influenced by it. I even attempted modifying variable names and changing speak to say, yet the outcome remained unchanged. Can someone shed some light on what may be causing this anomaly?

Answer №1

substitute name for this.name

var user = {
  name: "Sarah Smith",
  talk: function() {
    return "my name is " + this.name;
  },
  location: {
    street: '456 Maple Ave',
    city: 'Seattle',
    state: 'WA'
  }
}

document.write(user.talk());

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When should we utilize the React.Children API in React applications?

Exploring the potential use cases of the React.Children API. The documentation is a bit confusing for me (Using React v.15.2.0). https://facebook.github.io/react/docs/top-level-api.html#react.children According to the documentation, this.props.children ...

Ensure that ExpressJS response includes asynchronous try/catch handling for any errors thrown

Currently working with ExpressJS version 4.16.0, NodeJS version 10.15.0, along with KnexJS/Bookshelf, and encountering issues with error handling. While errors are successfully caught within my application, the problem arises when trying to retrieve the e ...

Summoning within a rigorous mode

I am facing an issue with my configuration object: jwtOptionsProvider.config({ tokenGetter: (store) => { return store.get('token'); }, whiteListedDomains: ['localhost'] }); In strict mode, I ...

Adjust the path-clip to properly fill the SVG

Is there a way to adjust the clip-path registration so that the line fills correctly along its path instead of top to bottom? Refer to the screenshots for an example. You can view the entire SVG and see how the animation works on codepen, where it is contr ...

Display the Angular UI grid containing data from the textboxes once the information has been submitted

I recently started working on an angularjs application and I am facing some challenges in finding the solution. Any advice or suggestions would be greatly appreciated. My goal is to dynamically display an angular UI-grid based on the text selected in the ...

Hover Action Failing to Activate

Can someone help me with a simple task? I have a pink box that should turn red when the user hovers over it, but the code doesn't seem to be working. If I can't figure this out, I might lose my job! <html> <head><title></tit ...

Changing an ng-repeat filter following the manual update of a text input

Utilizing jQuery auto-complete to automatically populate values as users type into a text input. <input type="text" ng-model="tags" name="tags" id="tags" value="" /> Subsequently, the ng-repeat is filtering content based on the entered text <di ...

Tips for changing the value of a TextField in React Material

I am faced with a challenge regarding a form that is populated with data from a specific country. This data is fetched from a GraphQL API using Apollo Client. By default, the data in the form is read-only. To make changes, the user needs to click on the e ...

Shake up your background with a random twist

Seeking assistance with customizing the Aerial template from HTML5UP. I am interested in selecting a scrolling background randomly from a pool of images. Can someone guide me on how to achieve this? Presently, the background is defined within a code block ...

Transform for loop from Axios post requests to promises

I am currently working with a loop of axios requests: for(const [number, response] of Object.entries(questions)){ axios.post( this.address+'surveypost', {"patientID": patientID, "questionID": number, "lik ...

Steps for dealing with uncaught exceptions in react and displaying a straightforward "internal error" notice on the user interface

When working on the node side, // Handling uncaught exceptions with Node.js process.on('uncaughtException', (error, source) => { fs.writeSync(process.stderr.fd, error, source); }); How can we achieve similar functionality in React for the ...

The nested ng-repeat on angular seems to be malfunctioning

Utilizing an ng-repeat to display the various sections of a form, I am facing an issue with displaying the questions within each section when using a nested ng-repeat. The values are not being displayed and I'm unsure why. Below is a sample JSON stru ...

Using ReactJS to Retrieve Input Value from Prompt Box and Save to Database

I'm currently developing a MERN application and I need to allow users to edit the food name by clicking on the prompt box that pops up when they click the Edit button. The approach I was following can be found in this link: [https://stackoverflow.com ...

Utilize Vue.js 3 and InertiaJs to Retrieve Session Information in Laravel 9

I am currently working on my initial Laravel project, incorporating Vuejs for the frontend. One of the key features of my application is allowing a Super admin to log in as a User (impersonate). By clicking on the Impersonate Button, the word impersonate g ...

Guide to pulling and showcasing information from XML at 30-second intervals using JQUERY AJAX and HTML

Seeking assistance as a beginner. Looking to retrieve and showcase data (HTML / PHP page) from XML every 30 seconds. XML FILE : <MAINData> <LiveData> <Field no="1">ENG ODI</Field> <Field no="2">ENG</Field> ...

Mongoose virtual population allows you to fetch related fields

When attempting to utilize virtual populate between two models that I've created, the goal is to retrieve all reviews with the tour id and display them alongside the corresponding tour. This is achieved by using query findById() to specifically show o ...

Is the PHP Ajax parameter missing during the upload process?

I'm attempting to do a simple upload, but I seem to be struggling. It could be that I'm not understanding it properly, or perhaps it's just too late at night for me to figure it out. After doing some research, I came across this example on ...

Using an if/else statement to detect if the iFrame is devoid of content

I have a customized youtube video section on my website template that can display either an embedded video or an image based on client preference. Currently, I am trying to implement code that will detect if the youtube video source is empty and then displ ...

Inject Dynamic HTML Content onto the Page or in a Pop-up Box

I am currently working on a C# asp.net Web Forms project that involves a credit card payment system. The system returns HTML code for a 3D payment page, but it does not auto-redirect. Here is a snippet of my request: thirdBasketItem.Price = "0.2"; basketI ...

Interacting with an XML file contained within a PHP variable using jQuery

I'm pretty new to programming, so please be patient with me =] Currently, I am working on passing a string from the user to an API using PHP. The API then responds with an XML file, which I store under $response. So far, everything is running smoothl ...