DEV Community

Vamshi Krishna
Vamshi Krishna

Posted on

JavaScript Key fundamentals Part - 3

6.Objects: A collection of properties and methods that represent a single entity.
.toString(): Returns a string representation of the object.

.valueOf(): Returns the primitive value of the object.

.hasOwnProperty(prop): Returns a Boolean indicating whether the object has the specified property.

.propertyIsEnumerable(prop): Returns a Boolean indicating whether the specified property is enumerable.

.isPrototypeOf(obj): Returns a Boolean indicating whether the object is a prototype of the specified object.

.concat(array): Returns a new array that is the result of concatenating the object with the specified array.

.join(separator): Joins all elements of an array into a string and returns the result, using the specified separator.

.pop(): Removes and returns the last element of an array.

.push(element): Adds one or more elements to the end of an array and returns the new length of the array.

.reverse(): Reverses the order of the elements in an array and returns the reversed array.

These are just a few examples of object methods in JavaScript. There are many others that you can use to manipulate and work with objects in your code.

Event handling: The process of responding to user actions such as mouse clicks, form submissions, and page loads.

<button id="myButton">Click me</button>

<script>
  var button = document.getElementById("myButton");

  button.addEventListener("click", function() {
    alert("Button was clicked!");
  });
</script>

Enter fullscreen mode Exit fullscreen mode

In this example, we first select the button element with the id of "myButton" using the document.getElementById() method. Then, we use the addEventListener method to attach a click event to the button. The addEventListener method takes two arguments: the type of event to listen for and the function to be executed when the event occurs.

When the button is clicked, the alert function will be called, displaying the message "Button was clicked!" on the screen.

Event handling is a crucial part of JavaScript programming, allowing you to respond to user interactions and update the content and behavior of your web pages dynamically.

DOM (Document Object Model): A tree-like representation of a web page, allowing JavaScript to modify the content and style of the page.

Top comments (0)

An Animated Guide to Node.js Event Loop

>> Check out this classic DEV post <<