Linked Questions

14 votes
6 answers
11k views

Are strings objects? [duplicate]

Here are two reasons to think strings are objects. First, you can create a string in the following way: var mystring = new String("asdf"); I'm under the impression that the constructor function ...
zjmiller's user avatar
  • 2,817
4 votes
1 answer
386 views

If a string is not an object, how am I able to use built-in methods? [duplicate]

When you create an object in JavaScript, you inherit properties from the Object prototype you can utilize. But a string is a primitive type, thus there is no prototype. So how am I able to use ...
Hayden's user avatar
  • 897
1 vote
0 answers
233 views

Primitive data vs Complex data in Javascript [duplicate]

I have studied about primitive data and complex data in w3schools. I searched elsewhere as well, but they don't give sense for me.The sentence stated below defines a primitive data. A primitive data ...
user avatar
0 votes
0 answers
134 views

How is it possible for a String literal to use methods and properties of String Object in JavaScript? [duplicate]

var str1 = "Sagar"; //String literal var str2 = new String("Sagar"); //String Object str1.length; // Output: 5 str2.length; // Output: 5 /* How is it possible for a string literal ...
Modu Sagar Kumar's user avatar
3 votes
0 answers
52 views

Why can't I define an iterator on a string? [duplicate]

Here's a contrived example. I can do this with an instance an array: function* cut () { for (let slice = 0; slice < 3; slice++) yield '🍰'; } const cake = ['🎂']; cake[Symbol.iterator] = cut; ...
customcommander's user avatar
1 vote
0 answers
31 views

How can primitive values have properties in JavaScript? [duplicate]

I have a little misunderstanding in JavaScript string type. According to JavaScript: The Definitive Guide, by David Flanagan, Any JavaScript value that is not a number, a string, a boolean, or ...
KarimS's user avatar
  • 3,902
368 votes
29 answers
83k views

What should every JavaScript programmer know? [closed]

Is there a set of things that every JavaScript programmer should know to be able to say "I know JavaScript"?
105 votes
7 answers
260k views

How to get an object's properties in JavaScript / jQuery?

In JavaScript / jQuery, if I alert some object, I get either [object] or [object Object] Is there any way to know: what is the difference between these two objects what type of Object is this what ...
Saiful's user avatar
  • 1,612
65 votes
2 answers
17k views

Difference between the javascript String Type and String Object?

I've been messing around with the ECMA-262 standard (ECMAScript Language Specification, 3rd edition, if it matters for this - I have not found any difference between the 3rd and 5th edition on String ...
thr's user avatar
  • 19.6k
35 votes
2 answers
7k views

Why can some constructors be called without using the `new` operator?

Please help me to understand why the following code works: var re = RegExp('\\ba\\b') ; console.log(re.test('a')) ; console.log(re.test('ab')) ; In the first line there is no new operator. ...
GetFree's user avatar
  • 43k
38 votes
3 answers
1k views

Why are there two kinds of JavaScript strings?

This one just stabbed me hard. I don't know if it's the case with all browsers (I don't have any other competent browser to test with), but at least Firefox has two kind of string objects. Open up ...
zneak's user avatar
  • 139k
15 votes
4 answers
5k views

Does Javascript's new operator do anything but make life difficult?

I come from the traditional web developer background where I can by no means claim to really know anything about Javascript, however I am trying. I currently have what I would describe as a fairly ...
George Mauer's user avatar
4 votes
2 answers
932 views

Difference between Object.create(foo) and new Object(foo)?

Why is that this code: var foo = {one: 1, two: 2}; var bar = new Object( foo ); bar.three = 3; bar.one = 100; document.write(bar.one); //100 document.write(foo.one); //100 results in bar.one & ...
Benny Tjia's user avatar
  • 4,883
5 votes
2 answers
1k views

String object versus literal - modifying the prototype?

I'm wondering why it seems that adding a method to the prototype of a string literal seems to work, but adding a property does not? I was playing with ideas in relation to this question, and have the ...
sje397's user avatar
  • 41.9k
5 votes
6 answers
266 views

JavaScript - behaviour of Function core object

As far as I understand, in JavaScript (Gecko variant) this: var a = new A(); is a syntactic sugar for something like this: var a = {}; a.__proto__ = A.prototype; A.call(a); Because of that, A() (...
Tomasz Zieliński's user avatar

15 30 50 per page