Linked Questions

13 votes
6 answers
10k 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,739
4 votes
1 answer
303 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
  • 807
1 vote
0 answers
209 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 ...
user avatar
0 votes
0 answers
123 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
51 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
29 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,872
368 votes
29 answers
82k 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"?
104 votes
7 answers
258k 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,602
66 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.3k
35 votes
2 answers
7k views

JavaScript: using constructor without operator 'new'

Please help me to understand why the following code works: <script> var re = RegExp('\\ba\\b') ; alert(re.test('a')) ; alert(re.test('ab')) ; </script> In the first line ...
GetFree's user avatar
  • 41.5k
38 votes
3 answers
927 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
  • 137k
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
914 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.6k
5 votes
6 answers
264 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