Coder Social home page Coder Social logo

fewpjs-js-fundamentals-calling-methods's Introduction

JavaScript Fundamentals: Calling Methods

Learning Goals

  • Define a JavaScript method

Introduction

In the previous lessons, we did a very important thing in the JavaScript language, we called a method. We glossed over some of the detail about what was happening at the technical level at that time. Let's put some new vocabulary around what we did.

Define a JavaScript Method

Let's consider the document.querySelector method.

This code calls the method querySelector. The method is said to be "defined in" the object document.

Calling is the same as running. We do that when we write:

document.querySelector(); // Notice the addition of ()

When we call document.querySelector(), we provide it an argument, a bit of text, a String of text that goes inside the ().

The method document.querySelector() expects us to provide a CSS identifier that will help us find the node we want as an argument.

If the document object finds an HTMLElement in its representation of the page, it returns it. Otherwise the method returns null.

The thing document.querySelector() returns is also an object. It, too, has both information and methods, state and behavior, properties and methods (they all mean the same thing). This HTMLElement instance has methods like remove().

Conclusion

JavaScript methods are actions that can be performed on objects. Objects have many useful methods that help us modify and iterate through them, for example. The DOM selection method document.querySelector() is a powerful tool for finding elements needed to make updates and changes to the DOM using methods like remove().

Resources

JavaScript Object Methods

fewpjs-js-fundamentals-calling-methods's People

Contributors

drakeltheryuujin avatar maxwellbenton avatar sgharms avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.