Object literals and constructor giving me errors

i am learning javascript objects and my first attempt to run this object below in my browser throws “uncaught syntax error” even though it works in the tutorial i watched.

//creating an object with object literals
var  emp1 = {};
emp1.firstName = "john";
emp1.lastName = "smith";
emp1.gender= "M";
emp1.designation = "sales department"

//creating an object with constructor
function createEmplyeeObject(firstName,lastName,gender, designation){
	this.firstName = firstName;
	this.lastName = lastName;
	this.gender = gender;
	this.designation = designation;
}

var emp3 = new createEmplyeeObject("Jim", "Halpert", "M", "Sales");

i would be very grateful for inputs to let me proceed. thanks in advance

which line points the error to?

btw. it’s Employee, not Emplyee

Hi, the code runs just fine for me so not sure what the problem is but it sounds like client-specific or unrelated to that code. Although in most if not all clients it wouldn’t make a difference I noticed you have a missing semi-colon after emp1.designation = "sales department"

[quote=“madahason2, post:1, topic:264917, full:true”]
i am learning javascript objects and my first attempt to run this object below in my browser throws “uncaught syntax error” even though it works in the tutorial i watched.[/quote]

As others have said, the code that you posted won’t throw any syntax errors.

Getting to a solution for you, can you please post the full code that your browser is running? There is likely to be something else in there that is causing the problem you’re experiencing.

thanks for the reply family. here is what happened.instead of using a semi colon throughout in the first code, i had a coma after the lastname and in my “stress” moment, i was not able to correct it until later. thanks for you help though, i really appreciate it.

Right
I also feel that you have to give full code to identify the error. i think there might be an error of syntax

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.