Object literal javascript


i need to create a log in form using object literal, any exampe may help?

Um this is an object literal:

var myObject = {}

Or with some properties

var myObject = { foo: 1, bar: 2 }

An object literal is just {}, it’s just the normal way you write objects in JavaScript code, its just basic syntax. We need quite a bit more context here, because what you’re asking is like “how do I write a login form using a string” or “how do I write a login form using a number”: the answer is, you can’t, they are just basic bits of syntax that you use in JavaScript. You can use string and numbers and objects and whatever in the JavaScript part of the code for a login form, but you need quite a bit more than just one of those things, you can’t even just use JavaScript.

1 Like

Thank you so much for your helpful comment. I have already created my first literal object including function…

// Set up the object 
	var loggedin = {
	  name : 'Alex',
	  email : 'example@gmail.com',
	  checkAdmin : function() {
		return "Hallo " + this.name; // Need "this" because inside function

	var sms = document.getElementById('sms');    // Get element
	sms.textContent = loggedin.checkAdmin();   // Update HTML with property of the object -->